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

I was given a set or re-write rules for a new website. I've never used them before and I'm trying to understand what we are doing here

RewriteEngine on  
RewriteCond %{HTTP_HOST} .   
RewriteCond %{HTTP_HOST} !^www\.myco\.com  
RewriteRule (.*)$1 [R=301,L]

RewriteCond $1 !^(CCSFG|images|fonts|themes|robots\.txt|index\.php) [NC]  
RewriteRule ^(.*)$ /index.php/$1 [L]

If I understand this, the first ruleset

RewriteCond %{HTTP_HOST} .   
RewriteCond %{HTTP_HOST} !^www\.myco\.com  
RewriteRule (.*)$1 [R=301,L]

If HTTP_HOST is anything AND
if HTTP_HOST doesn't start with
rewrite any page request to start with, return a 301 redirect and stop processing more rules

The next ruleset

RewriteCond $1 !^(CCSFG|images|fonts|ee-system|themes|robots\.txt|index\.php) [NC]  
RewriteRule ^(.*)$ /index.php/$1 [L]

says: If the request doesn't start with CCSFG,image or fonts or, etc (non-case sensitive) then rewrite the whole request to prepend /index.php/ and stop processing more rules

Is my interpretation correct?

If so, what would be the purpose of the second ruleset? Why would I want to prepend /index.php/ to these entries?

share|improve this question
up vote 3 down vote accepted

Yup, pretty much exactly.

The first RewriteCond %{HTTP_HOST} . exists so as to not redirect loop someone who isn't sending a host header - it's verifying that the host header variable contains at least one character.

The prepending behavior exists to force page requests to be handled by index.php, likely for pretty URLs - the exceptions are for locations that need to be served by a physically present file.

So, for /images/image2.jpg, it's letting Apache serve the file at that location, but for /contentpage/1/2/3 it's rewriting to /index.php/contentpage/1/2/3, letting the PHP app do its thing.

Actually, it's technically rewriting to //index.php/contentpage/1/2/3; it's clear that it has a changed base (from being in an htaccess file), and it's not taking that into account for its destination.

share|improve this answer
Thanks for this. Are you suggesting the leading / may be superfluous – uSlackr Oct 13 '11 at 12:32
Yup - it's not hurting anything, but it doesn't need to be there. – Shane Madden Oct 13 '11 at 14:36
One more question - what does the $1 represent in the last RewriteCond line? Is it the request? is $1 always the request? – uSlackr Oct 13 '11 at 17:09
It's the match in the below RewriteRule, the (.*). – Shane Madden Oct 13 '11 at 17:27
Really, so the conditions & rules are interpreted as a sort of unit? Curious. – uSlackr Oct 13 '11 at 18:07

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.