我试图在Django捕获请求之前使用Apache的Rewrite模块redirect用户。 我尝试了以下将用户从“test.php”redirect到“链接”页面
<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>
这种方法不起作用(当浏览到mydomain.com/test.php时,它不会将我redirect到“链接”页面)。
有没有办法用mod_wsgi实现重写?
它应该工作,如果mod_rewrite规则正确地写在正确的上下文。 这可能是你的失败,因为你正在做目录上下文中的内容,并使其设置错误的上下文。
为什么不使用更简单的RedirectPermanent指令:
RedirectPermanent /test.php http://mydomain.com/links
看到:
http://httpd.apache.org/docs/2.2/mod/mod_alias.html#redirectpermanent
这应该在DirectoryHost之外,并且在VirtualHost的顶层。