Apache cyclic redirection problem
- by slicedlime
I have an extremely weird problem with one of my sites. I run a number of blogs off a single apache2 server with a shared wordpress install. Each site has a www.domain.com main domain, but a ServerAlias of domain.com. This works fine for all the blogs except one, which instead of redirecting to www.domain.com redirects to domain.com, causing a cyclic redirection.
The configuration for each host looks like this:
<VirtualHost *:80>
ServerName www.domain.com
ServerAlias domain.com
DocumentRoot "/home/www/www.domain.com"
<Directory "/home/www/www.domain.com">
Options MultiViews Indexes Includes FollowSymLinks ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
As this didn't work, I tried a mod_rewrite rule for it, which still didn't redirect correctly. The weird thing here is that if i rewrite it to redirect to any other domain it will redirect correctly, even to another subdomain. So a rewrite rule for domain.com that redirects to foo.domain.com works, but not to www.domain.com. In the same way, trying to redirec to www.domain.com/foo/ ends me up with a redirection to domain.com/foo/.
Even weirder, I tried setting up domain.com as a completely separate virtual host, and ran this php test script as index.php on it:
<?php
header('Location: http://www.domain.com/' . $_SERVER["request_uri"]);
?>
Hitting domain.com still redirects to domain.com! Checking out the headers sent to the server verifies that I get exactly the redirect URL I wanted, except with the "www." stripped. The same script works like a charm if I replace www. with foo or redirect to any other domain.
This has now foiled me for a long time. I've diffed the vhosts configs for a working domain and the faulty one, and the only difference is the domain name itself. I've diffed the .htaccess files for both sites, and the only difference is a path related to the sharing of wordpress installation for the blogs:
php_value include_path ".:/home/www/www.domain.com/local/:/home/www/www.domain.com/"
I searched through everything in /etc (including apache conf) for the domain name of the faulty host and found nothing weird, searched through everything in /etc for one of the working ones to make sure it didn't differ, I even went so far to check on the DNS setup of two domains to make sure there wasn't anything strange going on.
Here's the response for the faulty one:
user@localhost dir $ wget -S domain.com
--2010-03-20 21:47:24-- http://domain.com/
Resolving domain.com... x.x.x.x
Connecting to domain.com|x.x.x.x|:80... connected.
HTTP request sent, awaiting response...
HTTP/1.1 301 Moved Permanently
Via: 1.1 ISA
Connection: Keep-Alive
Proxy-Connection: Keep-Alive
Content-Length: 0
Date: Sat, 20 Mar 2010 20:47:24 GMT
Location: http://domain.com/
Content-Type: text/html; charset=UTF-8
Server: Apache
X-Powered-By: PHP/5.2.10-pl0-gentoo
X-Pingback: http://domain.com/xmlrpc.php
Keep-Alive: timeout=15, max=100
Location: http://domain.com/ [following]
And a working one:
user@localhost dir $ wget -S domain.com
--2010-03-20 21:51:33-- http://domain.com/
Resolving domain.com... x.x.x.x
Connecting to domain.com|x.x.x.x|:80... connected.
HTTP request sent, awaiting response...
HTTP/1.1 301 Moved Permanently
Via: 1.1 ISA
Connection: Keep-Alive
Proxy-Connection: Keep-Alive
Content-Length: 0
Date: Sat, 20 Mar 2010 20:51:33 GMT
Location: http://www.domain.com/
Content-Type: text/html; charset=UTF-8
Server: Apache
X-Powered-By: PHP/5.2.10-pl0-gentoo
X-Pingback: http://www.domain.com/xmlrpc.php
Keep-Alive: timeout=15, max=100
Location: http://www.domain.com/ [following]
I'm stumped. I've had this problem for a long time, and I feel like I've tried everything. I can't see why the different domains would act differently under the same installation with the same settings.
Help :(