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'm using a very standard set of Rewrite rules for redirecting to the www domain. It works on one of my servers but not on the other.

I cant for the life of me figure out the problem because the other rewrite rules work except this one.

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

Is there some apache config setting that I need to change, or some conflicting rewrite rule?

share|improve this question
What do your server logs show when you enable verbose rewrite logging? – larsks Jun 23 '11 at 18:54

Things that can make this goes wrong:

  1. You put the rules in a .htaccess and .htaccess are disabled by a AllowOverride None
  2. You put the rules in a<Location> tag, that's unsupported (seach Location in that page)
  3. You put the rule in a DirectoryMatch directive and your directory is not matching the expression (not related, this rule could be put outside any Directory tag, it would be faster)
  4. You put this in an apache configuration file and forgot to reload apache (or you made a gracefull reload and it's stalled, try a hard reload)
  5. You put a rewriteRule before that one that is applied and this one is never read (a [L] tag?)
  6. you were drunk and edited the production server settings while you are testing the pre-production website, more seriously check that this instruction is in the VirtualHost which really match Servername or ServerAlias of
  7. you do not have mod_rewrite enabled on this server and this is in a <IfModule mod_rewrite.c> section -
  8. If you are redirected to a wrong place maybe you previously made a mistake, but the 301-permanent code imply your browser will not even re-call your fixed webserver until you close and re-open the browser

If you do not find do what @larsk said you to do, enable rewriteLog, especially to debug the #5.

share|improve this answer
Thanks for the thoughts, it was actually missing the [L] last constant – qodeninja Jul 7 '11 at 18:08
up vote 2 down vote accepted

You're missing the [L] rule in your redirect bozo! Yeah that fixed it!

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.