Redirecting through httpd.conf with Django and mod_wsgi

apache-2.2djangomod-wsgi

I am trying to use Apache's Rewrite module to redirect users before Django catches the request. I tried the following to redirect a user from "test.php" to the "links" page

<VirtualHost 10.0.0.3>
   WSGIDaemonProcess mydomain.com processes=1 threads=15 display-name=$
   WSGIProcessGroup mydomain.com

   DocumentRoot "/home/james/www"
   <Directory "/home/james/www">
   Options +FollowSymlinks
   RewriteEngine On
   RewriteRule ^test.php links [NC,R=301,L]

   Order allow,deny
   Allow from all 
   </Directory> 

   WSGIScriptAlias / "/home/james/www/app.wsgi"

   ServerName mydomain.com

</VirtualHost>

This approach does not work (when navigating to mydomain.com/test.php it does not redirect me to the "links" page, which does exists).

Is there a way to implement a Rewrite with mod_wsgi?

Best Answer

It should work if mod_rewrite rule is written properly and in the right context. It is probably failing for you because you are doing it inside the Directory context and have it setup wrong for that context.

Why not though use simpler RedirectPermanent directive:

RedirectPermanent /test.php http://mydomain.com/links

See:

http://httpd.apache.org/docs/2.2/mod/mod_alias.html#redirectpermanent

This should be outside of Directory context and at top level within VirtualHost.

Related Topic