使用Django / Apache / mod_wsgi从foo.com到www.foo.com 301时双击

时间:2013-05-24 15:19:30

标签: django apache mod-wsgi virtualhost http-status-code-301

我们有一个通过mod_wsgi在Apache上运行的Django应用程序。

我们的主要域名是foo.com(没有www),但我们也希望管理www请求,将它们重定向到带有301的主页。

我以这种方式设置了这个东西

<VirtualHost xxx.xxx.xxx.xxx:80>

   DocumentRoot /var/www/vhosts/foo.com/public
   ServerName foo.com
   ServerAlias www.foo.com

   Alias /media/  /var/www/vhosts/foo.com/public/media/
   Alias /static/ /var/www/vhosts/foo.com/public/static/

   RewriteEngine On

   RewriteCond %{HTTP_HOST}    !=foo.com [NC]
   RewriteRule ^(.*)$          http://foo.com/$1 [L,R=301]


   <Directory /var/www/vhosts/foo.com/public>
       Order allow,deny
       Allow from all
       AllowOverride All
   </Directory>

   WSGIDaemonProcess foo.com processes=5 threads=30 display-name=%{GROUP}
   WSGIProcessGroup foo.com

   WSGIScriptAlias / /var/www/vhosts/foo.com/fooproject/fooproject/wsgi.py

   LogLevel debug
   ErrorLog /var/www/vhosts/foo.com/logs/error.log
   CustomLog /var/www/vhosts/foo.com/logs/access.log combined

</VirtualHost>

一切正常,但我在www.foo.com上的每个请求都有双斜线

示例:

www.foo.com -> foo.com//
www.foo.com/ -> foo.com//
www.foo.com/page  -> foo.com//page

通常该规则适用于PHP站点。

可能是什么?有什么我可以看一下来理解它吗?

PS。我已将Django APPEND_SLASH设置为False

1 个答案:

答案 0 :(得分:1)

更改

RewriteRule ^(.*)$          http://foo.com/$1 [L,R=301]

RewriteRule ^(.*)$          http://foo.com$1 [L,R=301]