Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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'm going nuts here. Apache is completely ignoring both the RewriteCond and RewriteRule. I would expect this to error out as RewriteEngine has not been set to On. I had a bunch of other RewriteCond and RewriteRule lines that were working fine and when I checked the Rewrite log (I had enabled) it showed these two being skipped. I trimmed everything else to verify none of it was causing the issue, and sure enough, Apache happily proceeds nary an error with this configuration:

DocumentRoot /var/sites/public
<Directory /var/sites/public>
    AllowOverride None
    SetEnv APPLICATION_ENV production

    RewriteCond %{HTTP_HOST} !^$
    RewriteRule ^/(.*)$1 [L,R]

    Order allow,deny
    allow from all

I'm pretty sure that there is some glaring error here that I've blinded myself to by staring at it for too long. Any help would be appreciated.

Notes: I don't have this in a Vhost. There aren't any Vhosts in the config. I've removed the RewriteCond and it still doesn't throw any errors. I have tried this with RewriteEngine On as well.

share|improve this question

Just taking a quick look at it tells me that the RewriteCond won't match to anything except what appears to be nothing. Not sure how mod_rewrite feels about that.

What exactly are you trying to do with the rule?

For example, if you want it to match any domain but (www.) and forward it to, then you would have a rule like:

RewriteCond %{HTTP_HOST} !^(www.)?example\.com$
RewriteRule (.*)$1 [R,L]
share|improve this answer
Why wouldn't the RewriteCond match anything? As far as I read it, it says the HTTP_HOST isn't empty. It's straight from the docs. – coreyward Jun 21 '10 at 13:42

You want this as well:

RewriteCond %{HTTP_HOST} .

...or written a different way:

RewriteCond %{HTTP_HOST}!=""


RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^(www.)?example\.com$
RewriteRule (.*)$1 [R,L]
share|improve this answer

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.