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 can't get the RewriteCond %{HTTP_HOST} to trigger when I just use It just seems to ignore it, but and seem to trigger the rewrite condition. I'm probably missing something simple, and was hoping some more experienced eyes would be able to help.

<VirtualHost *:80>

    DocumentRoot /var/www/

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

I've tried these 3 settings (replacing the above)

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

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

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

This is really frustrating for me, because it looks so simple, but I am unable to figure it out. Does anyone have any ideas? All of DNS entries are set (i can access all of these sites directly from the browser, just the redirection is broken).

UPDATE: There was another virtualhost enabled under sites-enabled. After disabling it, everything seems to work. I don't really understand why, but i think that somehow the other virtualhost's settings were being used when was entered, and thus apache didn't find any RewriteRules.

share|improve this question
up vote 1 down vote accepted

Try to enable mod_rewrite debug with the following directive.

Start at level 3 and show us the result. Also please add your apache version.

share|improve this answer
I was unaware of mod_rewrite debug. It helped me find out the above problem. Thanks for your help. – Bill Zimmerman Aug 27 '10 at 13:50

Your Answer


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