mod_rewrite in .htaccess to Force www in URL Not Working
Setting up a new site today, I ran into a problem with a .htaccess not working.
It was a pretty simple solution, and was the result of a minor oversight my part.
Still, it took me about 10 minutes to realize the mistake I’d made.
I just thought I’d post here in case someone else makes the same mistake.
I searched for a while but didn’t find the answer… until it finally dawned on me, “duh, I forgot to include the RewriteEngine on directive!”
So, I had this:
Options -IndexesRewriteCond %{HTTP_HOST} ^site\.com [NC] RewriteRule ^(.*)$ http://www.site.com/$1 [R=301,L]
But should have had this:
Options -IndexesRewriteEngine on RewriteCond %{HTTP_HOST} ^site\.com [NC] RewriteRule ^(.*)$ http://www.site.com/$1 [R=301,L]
Forgetting that simple line, “RewriteEngine on”, caused me all kinds of headache. :)


August 30th, 2010 at 5:55 am
[...] mod_rewrite in .htaccess to Force www in URL Not Working (eddieoneverything.com) [...]
January 16th, 2011 at 2:24 pm
Don’t forget to exclude sub-domains when forcing www.
http://www.theblogaholic.com/2011/01/16/force-www-using-htaccess-except-for-subdomains/