473,407 Members | 2,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

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.handlers.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 2278
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.handlers.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_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-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.handlers.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_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-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.handlers.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_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-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.handlers.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_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-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.handlers.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_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-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_FILENAME 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_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-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.handlers.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_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-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.handlers.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_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-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_FILENAME 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_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-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_FILENAME} !-f
RewriteCond /var/www/btsgroup.de/htdocs/%{REQUEST_FILENAME} !-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_pythonsection of the apache config-file.
<Location "/py">
SetHandler python-program
PythonHandler django.core.handlers.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_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-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.handlers.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_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-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_FILENAME 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_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-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_FILENAME} !-f
RewriteCond /var/www/btsgroup.de/htdocs/%{REQUEST_FILENAME} !-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_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-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
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...
0
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
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...
9
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...
4
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...
9
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
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...
5
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...
3
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...
1
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: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.