Someone I'm working with committed a RewriteRule such as the following to SVN:

RewriteRule ^admin/ebay.*$ /yii.php/$1 [L]

I warned him that it may not work because there is no subgroup in the match that would correspond to the $1 backreference. It does work, and I'm perplexed. I'm pretty sure what he intended was either of the following:

RewriteRule ^admin/ebay.*$ /yii.php/$0 [L] # $0 is whole match

...or...

RewriteRule ^admin/ebay(.*)$ /yii.php/$1 [L] # $1 subgroup

Does Apache make an assumption about backreferences that I never knew about? Why does his RewriteRule (the top one) work?

link|improve this question
From what I can tell URIs always start with / so ^admin will never match anything. – Mark Wagner May 11 '11 at 18:29
There may be a configuration or circumstances in which that's true, but as far as I have ever seen, they do not begin with /. I just posted an answer to this particular issue. – Ezekiel Victor May 12 '11 at 17:04
feedback

2 Answers

up vote 3 down vote accepted

As it turns out, the $1 really doesn't do anything here. The following works just as well:

RewriteRule ^admin/ebay.*$ /yii.php [L]

(Notice no backreference at all in the rewrite part.)

This works because Yii is looking at $_SERVER['REQUEST_URI'] to figure out what the user intended. In fact Apache was just passing empty for the $1 backreference as expected.

So no server fault here. :)

link|improve this answer
+1 correct, any "unfilled" back references will be blank if used. – Chris S May 12 '11 at 17:14
feedback

Try setting RewriteLog and RewriteLogLevel. The log might give you a hint about where that value is coming from.

link|improve this answer
Thanks for the tips. I'm going to post an answer right now. – Ezekiel Victor May 12 '11 at 16:58
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.