1

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/"

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

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 :(

4
  • What is actually performing the redirect? Does your .htaccess file trigger the redirect or something in the PHP code? Nothing you've included above shows how the redirects are configured / triggered.
    – Insyte
    Mar 20, 2010 at 21:03
  • Meh, part of the .htaccess file fell away from the post, with the rewrite rule. Included it now.
    – slicedlime
    Mar 20, 2010 at 23:33
  • Still, that doesn't explain the php script rewrite... that one was done without any .htaccess at all and still ended up with a circular redirection.
    – slicedlime
    Mar 20, 2010 at 23:44
  • 2
    Have you tried opening the site directly from the host to rule out any funky dns issues? I.E., add an entry for www.domain.com and domain.com to /etc/hosts and then open the site with links from a command prompt. If you've setup a separate virtualhost (non wordpress site) and you're still getting redirected back to domain.com then i would be suspect of Via: 1.1 ISA in the http headers. A quick search reveals Microsoft Internet Security & Acceleration Server. A reverse proxy and caching server among other things. It could be causing problems.
    – anonymouse
    Mar 21, 2010 at 7:07

2 Answers 2

1

Awesome! A good answer was given by anonymouse in a comment to the post:

Have you tried opening the site directly from the host to rule out any funky dns issues? I.E., add an entry for www.domain.com and domain.com to /etc/hosts and then open the site with links from a command prompt. If you've setup a separate virtualhost (non wordpress site) and you're still getting redirected back to domain.com then i would be suspect of Via: 1.1 ISA in the http headers. A quick search reveals Microsoft Internet Security & Acceleration Server. A reverse proxy and caching server among other things. It could be causing problems

The problem was (well, is) the ISA server. I still have no idea why this happens since I don't run that server, but adding both hosts to /etc/hosts and locally doing a wget -S on it gave me the proper behavior.

I'll need to talk to the people running that server to see if they know what it's about, but at least that explains why I couldn't get any sense out of what was happening.

Edit: Fixed! Changing the "To" rule site name in the ISA server rule fixed it, even though link translation was off.

0

Wordpress has it's own built in rewrite mechanism and that's what's probably causing the redirect loop. Search the wp_options table options_value field for the domain name.

select * from wp_options where option_value like '%domain.com%'

Within the first few rows you should see the domain listed as http://domain.com. Change these to include the www prefix.

Edit:

One more thing to check. I noticed some weird behavior in a recent version of Firefox where it seemed to be caching .htaccess rules. Couldn't figure out what the heck was wrong with my rewrite rules but once i cleared the cache and restarted FF they magically started working.

1
  • Already checked the options table, checked it again now with that query... all instances of domain.com are prefixed with www in it. This happens not only with firefox but with links or wget (as in the logs I posted in the query). It'd be weird if it was about wordpress anyway, since it happened even with the standalone php script. The builtin rewrite in wordpress is actually what I posted as .htaccess by the way. It writes the .htaccess file with those rewrite rules.
    – slicedlime
    Mar 21, 2010 at 9:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .