1

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?

1 Answer 1

1

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.

2
  • Thank you. I do need the rewrite module since I have already have a file with rewrite that I want to use. How can I check the configuration issue and make sure the context is set up correctly?
    – James
    Dec 26, 2011 at 8:11
  • I would start by reading the Apache httpd documentation and understanding the difference between using RewriteRule inside of a Directory block and outside. Learn how to use the RewriteLog directive to log what mod_rewrite is doing and understand why it isn't applying your rule correctly. Dec 26, 2011 at 10:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .