httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Barney Boisvert" <>
Subject [users@httpd] mod_rewrite [redirect] discrepancy in Apache 2.0 : domain canonicalization
Date Thu, 30 Mar 2006 06:46:00 GMT
Hello all.  I've been admining various Apache servers for a number of
years, but this is my first post on this list, so go easy on me. ;)

I've got a site covered with URL rewrites, but I when adding a domain
canonicalization block, I get some weird behaviour.  I first saw it on
2.0.54, and upgraded to 2.0.55 and see the same behaviour.  Running
this all on a RedHat 8.0 (yeah, I know) box with a 2.4.18 kernel and
gcc 3.2.  Both Apaches compiled from source with this config:

./configure \
        --with-mpm=prefork \
        --enable-mods-shared="access auth auth_anon include log_config
env mime_magic cern_meta expires headers setenvif ssl mime autoindex
negotiation dir actions speling alias rewrite proxy proxy_http

Here's the offending rules, which [should] simply redirect anything to
the vhost with a host header other than (www.)?, back to
the same resource on

RewriteCond %{HTTP_HOST}        !^(www\.)?barneyb\.com  [NC]
RewriteCond %{HTTP_HOST}        !^$
RewriteRule ^/(.*)$   $1       [R=301,L]

However, the redirect uses the wrong (uncanonicalized) domain.  Here's
a trimmed transcript of a raw request (Host request header, Location
response header, and HTML snippet are of import):

GET /test/ HTTP/1.1

HTTP/1.1 301 Moved Permanently
Date: Thu, 30 Mar 2006 06:03:57 GMT
Server: Apache/2.0.55 (Unix) mod_ssl/2.0.55 OpenSSL/0.9.6b mod_jk2/2.0.4
Content-Length: 379
Content-Type: text/html; charset=iso-8859-1

<p>The document has moved <a href="">here</a>.</p>

You'll notice that in the Location response header, the domain used is
the domain passed in the Host request header, while in the body of the
returned page, the domain is the domain specified by the RewriteRule. 
The correct status code (301) is being returned.

Here's a transcript of the rewrite log (for the above request), and
you'll see that the correct URL is being created and redirected to
(the final line):

---------------------------------------------------------------------- - - [29/Mar/2006:22:06:11 --0800]
[][rid#820cb80/initial] (3) applying pattern
'^/(.*)$' to uri '/test/' - - [29/Mar/2006:22:06:11 --0800]
[][rid#820cb80/initial] (4) RewriteCond:
input='' pattern='!^(www\.)?barneyb\.com' => matched - - [29/Mar/2006:22:06:11 --0800]
[][rid#820cb80/initial] (4) RewriteCond:
input='' pattern='!^$' => matched - - [29/Mar/2006:22:06:11 --0800]
[][rid#820cb80/initial] (2) rewrite /test/ -> - - [29/Mar/2006:22:06:11 --0800]
[][rid#820cb80/initial] (2) explicitly forcing
redirect with - - [29/Mar/2006:22:06:11 --0800]
[][rid#820cb80/initial] (1) escaping for redirect - - [29/Mar/2006:22:06:11 --0800]
[][rid#820cb80/initial] (1) redirect to [REDIRECT/301]

I'm not sure where the discrepancy is coming from, since mod_rewrite
certainly seems to be doing it's job correctly, and the the proper URL
is getting into the response, just not in the Location header.  Of
course, the Location header's the one that matters; the in-HTML link
is pretty irrelevant.  On a whim, I also tried flipping the
UseCanonicalName on and off, and (as I expected) didn't change

The rewriting guide provided a similar solution to the same problem;
differences were irrelevant (ordering of the rule flags, no status
code spec).  Eliminating the differences proved to be no help.  I also
went looking in the source, but I'm not a C programmer, so I got lost
rather quickly, and before I was able to learn anything helpful. 
Google provided no help beyond a couple potential descriptions of this
same issue that pointed at a dead server.

Not a huge deal (I've survived without domain canonicalization to this
point ;) but at this point, I'm more curious as to why it's not
behaving as I expect, either because there some insidious bug, or (far
more likely) my expectations are wrong.  Thanks in advance for any
insight you can offer on the problem.


Barney Boisvert

Got Gmail? I have 100 invites.

The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:> for more info.
To unsubscribe, e-mail:
   "   from the digest:
For additional commands, e-mail:

View raw message