mod_wsgi, .htaccess and rewriterule

Posted by hadaraz on Server Fault See other posts from Server Fault or by hadaraz
Published on 2009-09-03T22:00:24Z Indexed on 2010/03/25 13:03 UTC
Read the original article Hit count: 572

Filed under:
|
|

I'm using several django projects running on the same apache instance through mod_wsgi, configured with virtualhost for each site, see the httpd.conf here. For one of the sites I want to use static-cache (staticgenerator), so I set up a directory with .htaccess file which contains:

RequestHeader unset X-Forwarded-Host
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteRule ^(.*) http://127.0.0.1:3456/$1 [P]

where 3456 is the django port on the server. Using this rewrite rule, the request is always forwarded to the mod_wsgi handler, even if the file or directory exists, and if the file index.html exists the request shows as request-path/index.html. I tried another setup:

RequestHeader unset X-Forwarded-Host
RewriteEngine on
RewriteBase /
RewriteCond $1 !-d
RewriteCond $1index.html !-f
RewriteRule ^(.*) http://127.0.0.1:3456/$1 [P]

but got almost the same results. All requests are transferred to the mod_wsgi handler, but the request path is now the original one. To sum it up:

  1. What is the correct RewriteCond to use here?
  2. How do you transfer a request to the mod_wsgi handler? Is it the right way?
  3. If that's not the way to do it, then how do you serve static files from a directory when they exist, and when they don't you serve from apache/mode_wsgi?

Thanks for your help.

© Server Fault or respective owner

Related posts about mod-wsgi

Related posts about rewriterules