0

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} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,NC]

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

1
  • 3
    What do your server logs show when you enable verbose rewrite logging?
    – larsks
    Jun 23, 2011 at 18:54

2 Answers 2

4

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 example.com.
  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.

1
  • Thanks for the thoughts, it was actually missing the [L] last constant
    – qodeninja
    Jul 7, 2011 at 18:08
2

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .