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

The following rewrite redirects to instead of /www/ is the DocumentRoot.

# Rewrite Rules for Example
RewriteEngine On
RewriteBase /

# Redirect from to
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule ^(.*)$$1 [R=301,L]

This redirect is in a VirtualHost *:80 with the settings:


Options +FollowSymLinks
DocumentRoot /www/

and the rewrite is inside <Directory />

Any ideas why it would do this? I looked into the Apache manual and it says that using ${HTTP_HOST} in your RewriteCond will add the host to the RewriteRule instead of just the URL-Path. Well this is a VERY common rewrite, and I've never seen this happen before.

share|improve this question
is there any way to say: add some extra words to a url using mod_rewrite? Example: change: detail.php?id=$2 to: pressure-valve (normal mod_rewrite url) to: search-friendly-intro-to-pressure-valve This would append to all urls in a certain section of a site , like product pages. POSSIBLE?? Please send answer to my email. THANKS ! – user69143 Feb 2 '11 at 0:38
up vote 1 down vote accepted

The problem was <Directory />. Once I updated it to <Directory /www/> it worked just fine.

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.