httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Karsten Br├Ąckelmann <>
Subject Re: [users@httpd] mod_rewrite Redirection ignoring the explicite code
Date Fri, 07 May 2010 22:15:05 GMT
Thanks Igor and Eric for your help. :)  However, I'm not convinced
that's the cause here. Below is a bare minimum example that shows the
weird behavior I started with...

On Fri, 2010-05-07 at 09:34 +1000, Igor Cicimov wrote:
> Your 301 rule is wrong. As i said it should match the URI parth
> meaning the part after the slash following the domain name and not the
> whole URL. So no http:// in the rewrite rule hope this makes it more
> clear.

Yeah, you're referring to this early part of the RewriteRule docs,

 "Pattern is [...]. On the first RewriteRule it is applied to the
  URL-path of the request; subsequent patterns are applied to the output
  of the last matched RewriteRule."

However, it is different with sub-sequent rules, and only those I use to
match a protocol. (I just want to paranoidly ensure I'm not redirecting
by accident. And the full code also supports more than 3xx only, by
using special mappings.)

So, here is a *minimal* stripped down example that demonstrates the
weird behavior I'm asking about.

  RewriteRule  ^/foo
  RewriteRule  ^http://       -                    [R=301,L]

  RewriteRule  ^/bar
  RewriteRule  ^(http://.*)$  $1                   [R=301,L]

Now, "GET /foo HTTP/1.1" redirects to the rewritten URI as expected, but
it ignores my explicit 301 return code and instead defaults to 302.

  HTTP/1.1 302 Found

The second one, "GET /bar HTTP/1.1", does work exactly as I expected, as
clearly shown in the result. Also, with the sub-sequent RewriteRules, it
does match the full URI as substituted before (checked this with another
debugging rule, appending a path).

  HTTP/1.1 301 Moved Permanently

The only difference I see -- as mentioned in my initial post -- is the
explicit substitution as opposed to "just keep it" by using the dash.
And since in this one case I do not want to add or change anything, but
keep it and just force the redirect if it matches (trailing slash in
working code), the RE backreference and substitution with itself,
verbatim and in full, just doesn't seem necessary.

However, if I do *not* do the useless substitute-with-self, I end up
with my 301 redirection code being ignored...

Again, do these results show a bug? Is the dash intended and expected to
always default to 302, no matter the explicit code given? Or do I still
not see what is wrong with the rules?


char *t="\10pse\0r\0dtu\0.@ghno\x4e\xc8\x79\xf4\xab\x51\x8a\x10\xf4\xf4\xc4";
main(){ char h,m=h=*t++,*x=t+2*h,c,i,l=*x,s=0; for (i=0;i<l;i++){ i%8? c<<=1:
(c=*++x); c&128 && (s+=h); if (!(h>>=1)||!t[s+h]){ putchar(t[s]);h=m;s=0;

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