开发者

Django app, wordpress blog, apache 301 canonical redirection -> why do I have infinite loop?

I have a django app at / (served by WSGI), and a wordpress blog at /blog/. I'm trying to setup a 301 redirection from example.com to www.example.com, and managed to do so, except the wordpress blog. Reaching the blog triggers an infinite redirect loop.

Apache configuration at /etc/apache2/sites-enabled/example.com

<VirtualHost *:80>
    ServerName example.com
    Redirect permanent / http://www.example.com/
</VirtualHost>

<VirtualHost *:80>
   ServerName www.example.com
   DocumentRoot /srv/www/example.com/public_html/
   Alias /blog "/srv/www/example.com/public_html"
</VirtualHost>

The wordpress blog has a .htaccess in the root directory /srv/www/example.com/public_html:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php开发者_开发技巧 [L]
</IfModule>


Ok, I found out why the server was giving infinite redirect.

Wordpress blog was configured (in settings) at example.com. So it would internally rewrite the URL from www.example.com/blog to example.com/blog. At this point my redirect (example.com -> www.example.com) would kick in, sending an infinite loop.

Solution was simply to set the site at 'www.example.com' and not 'example.com'. The configuration was correct.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜