[users@httpd] mod_rewrite [redirect] discrepancy in Apache 2.0 : domain canonicalization

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

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

----------------------------------------------------------------------
ServerName      www.barneyb.com
ServerAlias     barneyb.com
...
RewriteCond %{HTTP_HOST}        !^(www\.)?barneyb\.com  [NC]
RewriteCond %{HTTP_HOST}        !^$
RewriteRule ^/(.*)$             http://www.barneyb.com/$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
Host: monkey.com

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
Location: http://monkey.com/test/
Content-Length: 379
Content-Type: text/html; charset=iso-8859-1

...
<p>The document has moved <a href="http://www.barneyb.com/test/";>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):

----------------------------------------------------------------------
127.0.0.1 - - [29/Mar/2006:22:06:11 --0800]
[monkey.com/sid#81c46b8][rid#820cb80/initial] (3) applying pattern
'^/(.*)$' to uri '/test/'
127.0.0.1 - - [29/Mar/2006:22:06:11 --0800]
[monkey.com/sid#81c46b8][rid#820cb80/initial] (4) RewriteCond:
input='monkey.com:80' pattern='!^(www\.)?barneyb\.com' => matched
127.0.0.1 - - [29/Mar/2006:22:06:11 --0800]
[monkey.com/sid#81c46b8][rid#820cb80/initial] (4) RewriteCond:
input='monkey.com:80' pattern='!^$' => matched
127.0.0.1 - - [29/Mar/2006:22:06:11 --0800]
[monkey.com/sid#81c46b8][rid#820cb80/initial] (2) rewrite /test/ ->
http://www.barneyb.com/test/
127.0.0.1 - - [29/Mar/2006:22:06:11 --0800]
[monkey.com/sid#81c46b8][rid#820cb80/initial] (2) explicitly forcing
redirect with http://www.barneyb.com/test/
127.0.0.1 - - [29/Mar/2006:22:06:11 --0800]
[monkey.com/sid#81c46b8][rid#820cb80/initial] (1) escaping
http://www.barneyb.com/test/ for redirect
127.0.0.1 - - [29/Mar/2006:22:06:11 --0800]
[monkey.com/sid#81c46b8][rid#820cb80/initial] (1) redirect to
http://www.barneyb.com/test/ [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
anything.

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.

cheers,
barneyb

--
Barney Boisvert
bboisvert@xxxxxxxxx
360.319.6145
http://www.barneyb.com/

Got Gmail? I have 100 invites.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
   "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx



[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux