Reputation: 13
EDIT: The problem was that the domain was purchased at GoDaddy, but hosted at Endurance Internation Group (they own Hostgator and a few other small web hosts). Endurance doesn't have mod_rewrite activated by default, which is why this wasn't working.
I have hosted the site on GoDaddy and now everything works 100%.
I have a website that Google is indexing the www and non-www version of. I only want the non-www version. This is my current .htaccess code. The 301 redirects of individual files at the bottom work, but the www to non-www code at the top does not work.
What am I doing wrong?
RewriteEngine On
RewriteBase /
RewriteCond % ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
# Redirect old file path to new file path
Redirect 301 /aboutcarytreeservice.html http://example.com/about.html
Redirect 301 /carytreeservice.html http://example.com/services.html
Redirect 301 /treeremovaldurhamnc.html http://example.com/durham.html
Redirect 301 /treeservicedurhamnc.html http://example.com/durham.html
Redirect 301 /treeremovalraleighnc.html http://example.com/
Upvotes: 0
Views: 304
Reputation: 760
Try this:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
It will look to see if there is a "www" in the URL and cause a 301 redirect to the same URL (with "www" added) if it is not.
Upvotes: 0
Reputation: 785866
This condition is wrong:
RewriteCond % ^www.example.com [NC]
change it to:
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
Upvotes: 0