You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Joost de Heer <jo...@sanguis.xs4all.nl> on 2005/10/16 17:38:46 UTC

Strange mod_rewrite behaviour?

In the mod_rewrite examples page the following can be found:

RewriteEngine on
RewriteCond %{REQUEST_URI} !-U
RewriteRule ^(.*) http://webserverB.dom/$1

[Not related comment: shouldn't this be ^/(.*)]

A request for http://localhost/foo/bar results in the following log:

127.0.0.1 - - [16/Oct/2005:17:34:06 +0200] 
[windows.joost.localnet/sid#46a8b0][rid#4b1900/initial] (2) init rewrite 
engine with requested uri /foo/bar
127.0.0.1 - - [16/Oct/2005:17:34:06 +0200] 
[windows.joost.localnet/sid#46a8b0][rid#4b1900/initial] (3) applying pattern 
'^(.+)' to uri '/foo/bar'
127.0.0.1 - - [16/Oct/2005:17:34:06 +0200] 
[windows.joost.localnet/sid#46a8b0][rid#4c7a48/subreq] (2) init rewrite engine 
with requested uri /foo/bar
127.0.0.1 - - [16/Oct/2005:17:34:06 +0200] 
[windows.joost.localnet/sid#46a8b0][rid#4c7a48/subreq] (3) applying pattern 
'^(.+)' to uri '/foo/bar'
127.0.0.1 - - [16/Oct/2005:17:34:06 +0200] 
[windows.joost.localnet/sid#46a8b0][rid#4c7a48/subreq] (4) RewriteCond: 
input='/foo/bar' pattern='!-U' => matched
127.0.0.1 - - [16/Oct/2005:17:34:06 +0200] 
[windows.joost.localnet/sid#46a8b0][rid#4c7a48/subreq] (2) rewrite /foo/bar -> 
http://webserverB.dom//foo/bar
127.0.0.1 - - [16/Oct/2005:17:34:06 +0200] 
[windows.joost.localnet/sid#46a8b0][rid#4c7a48/subreq] (2) implicitly forcing 
redirect (rc=302) with http://webserverB.dom//foo/bar
127.0.0.1 - - [16/Oct/2005:17:34:06 +0200] 
[windows.joost.localnet/sid#46a8b0][rid#4c7a48/subreq] (1) escaping 
http://webserverB.dom//foo/bar for redirect
127.0.0.1 - - [16/Oct/2005:17:34:06 +0200] 
[windows.joost.localnet/sid#46a8b0][rid#4c7a48/subreq] (1) redirect to 
http://webserverB.dom//foo/bar [REDIRECT/302]
127.0.0.1 - - [16/Oct/2005:17:34:06 +0200] 
[windows.joost.localnet/sid#46a8b0][rid#4b1900/initial] (5) RewriteCond URI 
(-U) check: path=/foo/bar -> status=302
127.0.0.1 - - [16/Oct/2005:17:34:06 +0200] 
[windows.joost.localnet/sid#46a8b0][rid#4b1900/initial] (4) RewriteCond: 
input='/foo/bar' pattern='!-U' => not-matched
127.0.0.1 - - [16/Oct/2005:17:34:06 +0200] 
[windows.joost.localnet/sid#46a8b0][rid#4b1900/initial] (1) pass through /foo/bar

So instead of getting redirected, the -U seems to get applied again, sees the 
request resulted in a 302 redirect, and decides that it's a valid URL after 
all, so it's passed through, leading to a 404 error, instead of the redirect.

Am I misinterpreting the results, is the example wrong, or is something weird 
going on in mod_rewrite with -U?

Joost

Re: Strange mod_rewrite behaviour?

Posted by Joost de Heer <jo...@sanguis.xs4all.nl>.
André Malo wrote:
> * Joost de Heer wrote:

>>In the mod_rewrite examples page the following can be found:

>>RewriteEngine on
>>RewriteCond %{REQUEST_URI} !-U
>>RewriteRule ^(.*) http://webserverB.dom/$1

>>A request for http://localhost/foo/bar results in the following log:
>>
>>[windows.joost.localnet/sid#46a8b0][rid#4b1900/initial] (3) applying
>>pattern '^(.+)' to uri '/foo/bar'
> 
> 
> This cannot be. (.+ vs .*)

Because I typo'd the RewriteRule, it's (.+).

> Which version are we talking about anyway?

2.0.55 on Windows

Joost

Re: Strange mod_rewrite behaviour?

Posted by André Malo <nd...@perlig.de>.
* Joost de Heer wrote:

> In the mod_rewrite examples page the following can be found:
>
> RewriteEngine on
> RewriteCond %{REQUEST_URI} !-U
> RewriteRule ^(.*) http://webserverB.dom/$1
>
> [Not related comment: shouldn't this be ^/(.*)]

Yes.

> A request for http://localhost/foo/bar results in the following log:
>
> [windows.joost.localnet/sid#46a8b0][rid#4b1900/initial] (3) applying
> pattern '^(.+)' to uri '/foo/bar'

This cannot be. (.+ vs .*)

Anyway, the example is misleading if not wrong. -U only figures out whether 
the URL is accessible, not if the requested resource does exist.

> So instead of getting redirected, the -U seems to get applied again, sees
> the request resulted in a 302 redirect, and decides that it's a valid URL
> after all, so it's passed through, leading to a 404 error, instead of the
> redirect.

Well, it should probably get an [NS] on the rule.
Which version are we talking about anyway?

*sigh* I think, the only weird thingy here is the rewrite guide itself :-(

nd
-- 
"Eine Eieruhr", erklärt ihr Hermann, "besteht aus einem Ei. Du nimmst
das Ei und kochst es. Wenn es hart ist, sind fünf Minuten um. Dann weißt
du, daß die Zeit vergangen ist."
                             -- Hannes Hüttner in "Das Blaue vom Himmel"