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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.