Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


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?

share|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
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. :)

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

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

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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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