Return-Path: Delivered-To: apmail-httpd-users-archive@www.apache.org Received: (qmail 14078 invoked from network); 30 Mar 2006 06:46:32 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 30 Mar 2006 06:46:32 -0000 Received: (qmail 7840 invoked by uid 500); 30 Mar 2006 06:46:25 -0000 Delivered-To: apmail-httpd-users-archive@httpd.apache.org Received: (qmail 7221 invoked by uid 500); 30 Mar 2006 06:46:22 -0000 Mailing-List: contact users-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: users@httpd.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list users@httpd.apache.org Received: (qmail 7210 invoked by uid 99); 30 Mar 2006 06:46:22 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Mar 2006 22:46:22 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of bboisvert@gmail.com designates 66.249.92.195 as permitted sender) Received: from [66.249.92.195] (HELO uproxy.gmail.com) (66.249.92.195) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Mar 2006 22:46:21 -0800 Received: by uproxy.gmail.com with SMTP id m2so193219ugc for ; Wed, 29 Mar 2006 22:46:00 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=A2gck9Pa+56ZyXHVkjafzNOQnl+o3sL5AwTL5ee1KxN+dGU9NrIWEt7x/VmuyLjBySstgabConJc09Knm3/sKVC28pE3YPRLVNgKSHMQ1ptmdsPef8STikJvEp5jvafPXId9lUeq8gDDm0VhKQcGugZbvBPPsAe81DkZW1dfpm0= Received: by 10.78.31.18 with SMTP id e18mr45933hue; Wed, 29 Mar 2006 22:46:00 -0800 (PST) Received: by 10.78.32.13 with HTTP; Wed, 29 Mar 2006 22:46:00 -0800 (PST) Message-ID: Date: Wed, 29 Mar 2006 22:46:00 -0800 From: "Barney Boisvert" To: users@httpd.apache.org MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Virus-Checked: Checked by ClamAV on apache.org Subject: [users@httpd] mod_rewrite [redirect] discrepancy in Apache 2.0 : domain canonicalization X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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=3Dprefork \ --enable-mods-shared=3D"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=3D301,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=3Diso-8859-1 ...

The document has moved here= .

... ---------------------------------------------------------------------- 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.=20 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=3D'monkey.com:80' pattern=3D'!^(www\.)?barneyb\.com' =3D> matched 127.0.0.1 - - [29/Mar/2006:22:06:11 --0800] [monkey.com/sid#81c46b8][rid#820cb80/initial] (4) RewriteCond: input=3D'monkey.com:80' pattern=3D'!^$' =3D> 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.=20 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@gmail.com 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 for more info. To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org " from the digest: users-digest-unsubscribe@httpd.apache.org For additional commands, e-mail: users-help@httpd.apache.org