On Mar 9, 12:02 am, "Danilo" <[EMAIL PROTECTED]> wrote: > On 8 Mrz., 12:18, [EMAIL PROTECTED] wrote: > > > > > On Mar 8, 9:50 pm, "Danilo" <[EMAIL PROTECTED]> wrote: > > > > 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 -- http://mail.python.org/mailman/listinfo/python-list