Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 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.

share|improve this answer
    
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 '11 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. –  Graham Dumpleton Dec 26 '11 at 10:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.