Hi Brian, I ran into this when I started with mod_wsgi... It has to do with mod_rewrite and the order of processing. The answer is to use the [PT] flag on your rewrite rule -- read below:
>From http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html... - '*passthrough|PT*' (*p*ass *t*hrough to next handler) This flag forces the rewrite engine to set the uri field of the internal request_rec structure to the value of thefilename field. This flag is just a hack to enable post-processing of the output of RewriteRule directives, usingAlias, ScriptAlias, Redirect, and other directives from various URI-to-filename translators. For example, to rewrite /abc to /def using mod_rewrite <http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html>, and then /def to /ghi using mod_alias<http://httpd.apache.org/docs/2.0/mod/mod_alias.html> : RewriteRule ^/abc(.*) /def$1 [PT] Alias /def /ghi If you omit the PT flag, mod_rewrite will rewrite uri=/abc/... to filename=/def/... as a full API-compliant URI-to-filename translator should do. Then mod_alias will try to do a URI-to-filename transition, which will fail. Note: *You must use this flag if you want to mix directives from different modules which allow URL-to-filename translators*. The typical example is the use of mod_alias<http://httpd.apache.org/docs/2.0/mod/mod_alias.html> and mod_rewrite <http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html>. At least, that seems to be your issue! Sincerely, Jason Garber On Sat, Feb 26, 2011 at 11:49 PM, Brian Neal <[email protected]> wrote: > I am running a Django application at the root of a virtualhost using > mod_wsgi in daemon mode. > > Can I use mod_rewrite to rewrite urls before they get to the wsgi > application? For example, my old site had URLs of the form: > > /modules.php?name=News&file=article&sid=500 > > I'd like to map that to > > /news/story/500/ > > I've played around with mod_rewrite: > > RewriteEngine on > RewriteCond %{QUERY_STRING} ^name=News&file=([a-z_]+)&sid=([0-9]+) > RewriteRule ^modules\.php /news/story/%2/ [R=301,L] > > But it doesn't seem to work. Even this doesn't work: > > RewriteCond %{QUERY_STRING} test > RewriteRule .* /test/ [R=301,L] > > which makes me think that mod_rewrite isn't even running when mod_wsgi > is in this configuration. > > Is there a way to make this work? > I suppose I could try to process the old URL in my Django application > and return a redirect there. > > Thanks, > BN > > -- > You received this message because you are subscribed to the Google Groups > "modwsgi" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/modwsgi?hl=en. > > -- You received this message because you are subscribed to the Google Groups "modwsgi" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/modwsgi?hl=en.
