2

Related 1 2 3

But this question is slightly different.

Say I have a RewriteRule like:

RewriteRule ^test/([\w]*)/([\w]*)/([\w]*)/?$ go.php?q=THREE_$1_$2_$3

So http://localhost/test/a/b/c gets rewritten to http://localhost/go.php?q=THREE_a_b_c

Now say I want to explicitly catch the condition where the middle parameter is left out and a double slash results, like http://localhost/test/a//c

So I write a rule like:

RewriteRule ^test/([\w]*)//([\w]*)/?$ go.php?q=TWO_$1_(EMPTY)_$2

BUT ALAS, the rule never matches, it seems RewriteRule does not see the double slash, even though the double slash is preserved in both %{THE_REQUEST} and %{REQUEST_URI}.

So I write a rule like:

RewriteCond %{REQUEST_URI} //
RewriteRule ^test/([\w]*)/([\w]*)/?$ go.php?q=TWO_$1_(NONE)_$2

And that works, because the RewriteCond only applies if there's a double slash in the REQUEST_URI. But as you can see I still have to assume there's NO double slash there when parsing with the regex.

All this is very disturbing because I thought RewriteRule worked on %{REQUEST_URI} but it turns out it doesn't, it works on something else (a double slash stripped version..?)

My question really is, if not raw %{REQUEST_URI} then what does RewriteRule feed on?

Community
  • 1
  • 1
bobobobo
  • 64,917
  • 62
  • 258
  • 363

1 Answers1

0

Not sure about this, but your second rule:

RewriteRule ^test/([\w]*)//([\w]*)/([\w]*)/?$ go.php?q=TWO_$1_(EMPTY)_$2

appears to be trying to match a URL like this:

http://localhost/test/a//b/c

or like this:

http://localhost/test/a///c

If you change the second rule to:

RewriteRule ^test/([\w]*)//([\w]*)/?$ go.php?q=TWO_$1_(EMPTY)_$2

it should work.

Edit:

The real answer!

Apache removes empty path segments

Now I know the issue is not just an incorrect regex, I searched for the answer.

Community
  • 1
  • 1
thirtydot
  • 224,678
  • 48
  • 389
  • 349
  • Error in the post. But :) That's _what you'd think_ but it actually does not work that way. – bobobobo Dec 23 '10 at 22:09
  • It doesn't seem particularly fair for you to downvote when I wrote what I did solely because of an error you made in your question :/ – thirtydot Dec 23 '10 at 22:23
  • I know. But I only did it to prevent driveby upvotes. Undone. But this still doesn't really answer the question which is: if not raw %{REQUEST_URI} then what does RewriteRule feed on? – bobobobo Dec 23 '10 at 22:39
  • Well, from Gumbo's answer, it appears that RewriteRule feeds on Apache's own internal "normalized" URI which has changes such as the removal of empty path segments. – thirtydot Dec 23 '10 at 22:50