473,661 Members | 2,453 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Configuration: Apache + mod_python

Hi there,

is it possible to create a rewrite rule to send every server-request
to the directory /py? But only if the file does not exists on the
server.

This is my mod_python section of the apache config-file.

<Location "/py">
SetHandler python-program
PythonHandler django.core.han dlers.modpython
PythonPath "['/var/www/mydomain.com/htdocs/py'] + sys.path"
SetEnv DJANGO_SETTINGS _MODULE myapp.settings
PythonDebug Off
</Location>

Thanks.

Mar 8 '07 #1
5 2285
On Mar 8, 9:50 pm, "Danilo" <dbrab...@gmail .comwrote:
Hi there,

is it possible to create a rewrite rule to send every server-request
to the directory /py? But only if the file does not exists on the
server.

This is my mod_python section of the apache config-file.

<Location "/py">
SetHandler python-program
PythonHandler django.core.han dlers.modpython
PythonPath "['/var/www/mydomain.com/htdocs/py'] + sys.path"
SetEnv DJANGO_SETTINGS _MODULE myapp.settings
PythonDebug Off
</Location>
For the more general case of where a HTTP 404 error would otherwise be
returned, indicating that a resource could not be found, as opposed to
an actual physical file, you can just use:

ErrorDocument 404 /py

This would be simpler than using mod_rewrite. I can't remember though
whether the handler when triggered in this case can change the
response status to something other than 404.

You could use mod_rewrite if you really must, but not sure how it
would interact with virtual resources managed by some handler where no
actual file exists. To be practical you would probably want to
restrict the scope of mod_rewrite to specific contexts.

Quoting an example from very good book "The Definitive Guide to Apache
mod_rewrite", you can do something similar to:

RewriteEngine On
# If its not here ...
RewriteCond %{REQUEST_FILEN AME} !-f
RewriteCond %{REQUEST_FILEN AME} !-d
# Look here instead ...
RewriteRule ^/images/(.*) /pics/$1 [PT]

In this case it is causing lookups for images to be made in two
places, but your case wouldn't be much different.

Graham

Mar 8 '07 #2
On 8 Mrz., 12:18, Graham.Dumple.. .@gmail.com wrote:
On Mar 8, 9:50 pm, "Danilo" <dbrab...@gmail .comwrote:
Hi there,
is it possible to create a rewrite rule to send every server-request
to the directory /py? But only if the file does not exists on the
server.
This is my mod_python section of the apache config-file.
<Location "/py">
SetHandler python-program
PythonHandler django.core.han dlers.modpython
PythonPath "['/var/www/mydomain.com/htdocs/py'] + sys.path"
SetEnv DJANGO_SETTINGS _MODULE myapp.settings
PythonDebug Off
</Location>

For the more general case of where a HTTP 404 error would otherwise be
returned, indicating that a resource could not be found, as opposed to
an actual physical file, you can just use:

ErrorDocument 404 /py

This would be simpler than using mod_rewrite. I can't remember though
whether the handler when triggered in this case can change the
response status to something other than 404.

You could use mod_rewrite if you really must, but not sure how it
would interact with virtual resources managed by some handler where no
actual file exists. To be practical you would probably want to
restrict the scope of mod_rewrite to specific contexts.

Quoting an example from very good book "The Definitive Guide to Apache
mod_rewrite", you can do something similar to:

RewriteEngine On
# If its not here ...
RewriteCond %{REQUEST_FILEN AME} !-f
RewriteCond %{REQUEST_FILEN AME} !-d
# Look here instead ...
RewriteRule ^/images/(.*) /pics/$1 [PT]

In this case it is causing lookups for images to be made in two
places, but your case wouldn't be much different.

Graham
The rewrite rule works, but now every request ist send to /py.
This is my .conf:

<VirtualHost *>
DocumentRoot /var/www/mydomain.com/htdocs
ServerName mydomain.com
ServerAlias www.mydomain.com

<Location "/py">
SetHandler python-program
PythonHandler django.core.han dlers.modpython
PythonPath "['/var/www/mydomain.com/htdocs/py'] + sys.path"
SetEnv DJANGO_SETTINGS _MODULE myapp.settings
PythonDebug Off
</Location>

RewriteEngine On
# If its not here...
RewriteCond %{REQUEST_FILEN AME} !-f
RewriteCond %{REQUEST_FILEN AME} !-d
# Look here instead...
RewriteRule (.*) /py$1 [PT]

ErrorLog /var/www/mydomain.com/logs/error.log
CustomLog /var/www/mydomain.com/logs/access.log common
</VirtualHost>

Any ideas what is wrong?

Mar 8 '07 #3
On Mar 9, 12:02 am, "Danilo" <dbrab...@gmail .comwrote:
On 8 Mrz., 12:18, Graham.Dumple.. .@gmail.com wrote:
On Mar 8, 9:50 pm, "Danilo" <dbrab...@gmail .comwrote:
Hi there,
is it possible to create a rewrite rule to send every server-request
to the directory /py? But only if the file does not exists on the
server.
This is my mod_python section of the apache config-file.
<Location "/py">
SetHandler python-program
PythonHandler django.core.han dlers.modpython
PythonPath "['/var/www/mydomain.com/htdocs/py'] + sys.path"
SetEnv DJANGO_SETTINGS _MODULE myapp.settings
PythonDebug Off
</Location>
For the more general case of where a HTTP 404 error would otherwise be
returned, indicating that a resource could not be found, as opposed to
an actual physical file, you can just use:
ErrorDocument 404 /py
This would be simpler than using mod_rewrite. I can't remember though
whether the handler when triggered in this case can change the
response status to something other than 404.
You could use mod_rewrite if you really must, but not sure how it
would interact with virtual resources managed by some handler where no
actual file exists. To be practical you would probably want to
restrict the scope of mod_rewrite to specific contexts.
Quoting an example from very good book "The Definitive Guide to Apache
mod_rewrite", you can do something similar to:
RewriteEngine On
# If its not here ...
RewriteCond %{REQUEST_FILEN AME} !-f
RewriteCond %{REQUEST_FILEN AME} !-d
# Look here instead ...
RewriteRule ^/images/(.*) /pics/$1 [PT]
In this case it is causing lookups for images to be made in two
places, but your case wouldn't be much different.
Graham

The rewrite rule works, but now every request ist send to /py.
This is my .conf:

<VirtualHost *>
DocumentRoot /var/www/mydomain.com/htdocs
ServerName mydomain.com
ServerAliaswww. mydomain.com

<Location "/py">
SetHandler python-program
PythonHandler django.core.han dlers.modpython
PythonPath "['/var/www/mydomain.com/htdocs/py'] + sys.path"
SetEnv DJANGO_SETTINGS _MODULE myapp.settings
PythonDebug Off
</Location>

RewriteEngine On
# If its not here...
RewriteCond %{REQUEST_FILEN AME} !-f
RewriteCond %{REQUEST_FILEN AME} !-d
# Look here instead...
RewriteRule (.*) /py$1 [PT]

ErrorLog /var/www/mydomain.com/logs/error.log
CustomLog /var/www/mydomain.com/logs/access.log common
</VirtualHost>

Any ideas what is wrong?
I did say you would probably need to restrict the scope of the
mod_rewrite rule to a specific context. In particular, put it inside
of a Directory directive corresponding to the file system directory
where your files live. Where you have it as the moment,
REQUEST_FILENAM E probably will not resolve to anything as Apache
hasn't yet matched it to the filesystem. Thus:

<Directory /some/path/to/document/root>

RewriteEngine On
# If its not here...
RewriteCond %{REQUEST_FILEN AME} !-f
RewriteCond %{REQUEST_FILEN AME} !-d
# Look here instead...
RewriteRule (.*) /py$1 [PT]
</Directory>

Graham

Mar 8 '07 #4
On 8 Mrz., 22:23, Graham.Dumple.. .@gmail.com wrote:
On Mar 9, 12:02 am, "Danilo" <dbrab...@gmail .comwrote:
On 8 Mrz., 12:18, Graham.Dumple.. .@gmail.com wrote:
On Mar 8, 9:50 pm, "Danilo" <dbrab...@gmail .comwrote:
Hi there,
is it possible to create a rewrite rule to send every server-request
to the directory /py? But only if the file does not exists on the
server.
This is my mod_python section of the apache config-file.
<Location "/py">
SetHandler python-program
PythonHandler django.core.han dlers.modpython
PythonPath "['/var/www/mydomain.com/htdocs/py'] + sys.path"
SetEnv DJANGO_SETTINGS _MODULE myapp.settings
PythonDebug Off
</Location>
For the more general case of where a HTTP 404 error would otherwise be
returned, indicating that a resource could not be found, as opposed to
an actual physical file, you can just use:
ErrorDocument 404 /py
This would be simpler than using mod_rewrite. I can't remember though
whether the handler when triggered in this case can change the
response status to something other than 404.
You could use mod_rewrite if you really must, but not sure how it
would interact with virtual resources managed by some handler where no
actual file exists. To be practical you would probably want to
restrict the scope of mod_rewrite to specific contexts.
Quoting an example from very good book "The Definitive Guide to Apache
mod_rewrite", you can do something similar to:
RewriteEngine On
# If its not here ...
RewriteCond %{REQUEST_FILEN AME} !-f
RewriteCond %{REQUEST_FILEN AME} !-d
# Look here instead ...
RewriteRule ^/images/(.*) /pics/$1 [PT]
In this case it is causing lookups for images to be made in two
places, but your case wouldn't be much different.
Graham
The rewrite rule works, but now every request ist send to /py.
This is my .conf:
<VirtualHost *>
DocumentRoot /var/www/mydomain.com/htdocs
ServerName mydomain.com
ServerAliaswww. mydomain.com
<Location "/py">
SetHandler python-program
PythonHandler django.core.han dlers.modpython
PythonPath "['/var/www/mydomain.com/htdocs/py'] + sys.path"
SetEnv DJANGO_SETTINGS _MODULE myapp.settings
PythonDebug Off
</Location>
RewriteEngine On
# If its not here...
RewriteCond %{REQUEST_FILEN AME} !-f
RewriteCond %{REQUEST_FILEN AME} !-d
# Look here instead...
RewriteRule (.*) /py$1 [PT]
ErrorLog /var/www/mydomain.com/logs/error.log
CustomLog /var/www/mydomain.com/logs/access.log common
</VirtualHost>
Any ideas what is wrong?

I did say you would probably need to restrict the scope of the
mod_rewrite rule to a specific context. In particular, put it inside
of a Directory directive corresponding to the file system directory
where your files live. Where you have it as the moment,
REQUEST_FILENAM E probably will not resolve to anything as Apache
hasn't yet matched it to the filesystem. Thus:

<Directory /some/path/to/document/root>

RewriteEngine On
# If its not here...
RewriteCond %{REQUEST_FILEN AME} !-f
RewriteCond %{REQUEST_FILEN AME} !-d
# Look here instead...
RewriteRule (.*) /py$1 [PT]

</Directory>

Graham
Thank you.

the RewriteCond just needs the absolute path:

RewriteEngine On
# If its not here...
RewriteCond /var/www/btsgroup.de/htdocs/%{REQUEST_FILEN AME} !-f
RewriteCond /var/www/btsgroup.de/htdocs/%{REQUEST_FILEN AME} !-d
# Look here instead...
RewriteRule (.*) /py$1 [PT]

Thanks
dan

Mar 9 '07 #5
On Mar 9, 7:09 pm, "Danilo" <dbrab...@gmail .comwrote:
On 8 Mrz., 22:23, Graham.Dumple.. .@gmail.com wrote:
On Mar 9, 12:02 am, "Danilo" <dbrab...@gmail .comwrote:
On 8 Mrz., 12:18, Graham.Dumple.. .@gmail.com wrote:
On Mar 8, 9:50 pm, "Danilo" <dbrab...@gmail .comwrote:
Hi there,
is it possible to create a rewrite rule to send every server-request
to the directory /py? But only if the file does not exists on the
server.
This is mymod_pythonsec tion of the apache config-file.
<Location "/py">
SetHandler python-program
PythonHandler django.core.han dlers.modpython
PythonPath "['/var/www/mydomain.com/htdocs/py'] + sys.path"
SetEnv DJANGO_SETTINGS _MODULE myapp.settings
PythonDebug Off
</Location>
For the more general case of where a HTTP 404 error would otherwise be
returned, indicating that a resource could not be found, as opposed to
an actual physical file, you can just use:
ErrorDocument 404 /py
This would be simpler than using mod_rewrite. I can't remember though
whether the handler when triggered in this case can change the
response status to something other than 404.
You could use mod_rewrite if you really must, but not sure how it
would interact with virtual resources managed by some handler where no
actual file exists. To be practical you would probably want to
restrict the scope of mod_rewrite to specific contexts.
Quoting an example from very good book "The Definitive Guide to Apache
mod_rewrite", you can do something similar to:
RewriteEngine On
# If its not here ...
RewriteCond %{REQUEST_FILEN AME} !-f
RewriteCond %{REQUEST_FILEN AME} !-d
# Look here instead ...
RewriteRule ^/images/(.*) /pics/$1 [PT]
In this case it is causing lookups for images to be made in two
places, but your case wouldn't be much different.
Graham
The rewrite rule works, but now every request ist send to /py.
This is my .conf:
<VirtualHost *>
DocumentRoot /var/www/mydomain.com/htdocs
ServerName mydomain.com
ServerAliaswww. mydomain.com
<Location "/py">
SetHandler python-program
PythonHandler django.core.han dlers.modpython
PythonPath "['/var/www/mydomain.com/htdocs/py'] + sys.path"
SetEnv DJANGO_SETTINGS _MODULE myapp.settings
PythonDebug Off
</Location>
RewriteEngine On
# If its not here...
RewriteCond %{REQUEST_FILEN AME} !-f
RewriteCond %{REQUEST_FILEN AME} !-d
# Look here instead...
RewriteRule (.*) /py$1 [PT]
ErrorLog /var/www/mydomain.com/logs/error.log
CustomLog /var/www/mydomain.com/logs/access.log common
</VirtualHost>
Any ideas what is wrong?
I did say you would probably need to restrict the scope of the
mod_rewrite rule to a specific context. In particular, put it inside
of a Directory directive corresponding to the file system directory
where your files live. Where you have it as the moment,
REQUEST_FILENAM E probably will not resolve to anything as Apache
hasn't yet matched it to the filesystem. Thus:
<Directory /some/path/to/document/root>
RewriteEngine On
# If its not here...
RewriteCond %{REQUEST_FILEN AME} !-f
RewriteCond %{REQUEST_FILEN AME} !-d
# Look here instead...
RewriteRule (.*) /py$1 [PT]
</Directory>
Graham

Thank you.

the RewriteCond just needs the absolute path:

RewriteEngine On
# If its not here...
RewriteCond /var/www/btsgroup.de/htdocs/%{REQUEST_FILEN AME} !-f
RewriteCond /var/www/btsgroup.de/htdocs/%{REQUEST_FILEN AME} !-d
# Look here instead...
RewriteRule (.*) /py$1 [PT]
Doing that would probably be considered bad practice. I think the
problem was I neglected to mention you would have to change your
RewriteRule to add a slash when used in Directory directive. Ie., use:

<Directory /var/www/btsgroup.de/htdocs>

RewriteEngine On
# If its not here...
RewriteCond %{REQUEST_FILEN AME} !-f
RewriteCond %{REQUEST_FILEN AME} !-d
# Look here instead...
RewriteRule (.*) /py/$1 [PT]

</Directory>

Note the slash after /py.

This works for me when I test it.
Graham

Mar 9 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2918
by: digidalmation | last post by:
Hello all. I've been trying to get my linux server to run mod_python. It's a Mandrake 10 linux box, and apache/mod_python are installed from rpms. apache2-mod_python-2.0.48_3.1.3-1mdk apache2-2.0.48-6mdk The rpm installed the python module as: /usr/lib/apache2-extramodules/mod_python.so And added a config file for apache:
0
3307
by: Christopher | last post by:
I am running: Fedora Core 1 Python 2.4 Apache 1.3.3 mod_python 2.7.11 When I try to access the test mptest.py file I receive: > Internal Server Error
1
2781
by: neha | last post by:
hi, i m trying to integrate python with apache on linux.For this i m using mod_python. I dont see any problem with the versions of python,apache and mod_python i m using. the versions i m using are apache version2. mod_python v3.1.14 python2.4 The problem is,when i m running my python script,after starting apache
9
3753
by: Matt Helm | last post by:
I am starting the design phase of a large project (ERP) where the backend will mostly be Python (or Ruby) providing web services. In this type of usage, is there any benenfit to running under Apache as opposed to a pure Python solution using Medusa, TwistedMatrix, or the like? Thanks, Matt
4
1860
by: Simon Johnson | last post by:
Dear All, I have decided to take the big plunge and drop the Microsoft platform and use Mod_Python and Apache in it's place. I've never used Linux before this project so it's a really big learning curve, but so far it's going well. I've managed to create some simple pages using the basic of Python. One of the questions I have is: How do you cache stuff in memory? Say
9
4923
by: cyberco | last post by:
And I thought this would be trivial...getting mod_python to run within apache on windows XP. ============= mod_python 3.2.8 apache 2.0.55 python2.4 winxp =============
0
1119
by: bashustbiju | last post by:
Hi Please some one help for configuring apache to use python scripts I made some changes. the index.py script contains the entry from mod_python import apache from mod_python import Session, Cookie, util def index(req):
5
3103
by: m.banaouas | last post by:
Hi, bonjour, witch versions are suitable to use for apache & mod_python ? Can i install and use "Apache 2.2.3" & "mod_python 3.2.10" (most recent versions) without facing any known major issue ? thanks for any help.
3
4932
by: joe jacob | last post by:
I configured apache to execute python scripts using mod_python handler. I followed below mentioned steps to configure apache. 1. In http.conf I added <Directory "D:/softwares/Apache2.2/htdocs"> AddHandler mod_python .py PythonHandler mptest PythonDebug On </Directory>
1
4281
by: NccWarp9 | last post by:
Hello, im using Apache HTTPD 2.2.8 with mod_python/3.3.1 Python/2.4.3 on Windows and having truble starting pythone, any help would be appreciated .. Im getting this error: make_obcallback: could not import mod_python.apache.\n
0
8855
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8545
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8633
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7364
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5653
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4179
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1986
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1743
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.