Trying to clean up duplicate content with .htaccess
I’m trying to route the www. to the non www
To route the /index.html to /
Can you help me and see if this .htaccess will work?
Thank You
RewriteEngine On
# Redirect from www to non www
RewriteCond %{HTTP_HOST} ^www\\.site\\.com$ [NC]
RewriteRule ^(.*)$ http://site.com/$1 [L,R=301]
# Rewrite index.html to root
RewriteRule ^index\\.html$ http://site.com/ [L,R=301]
dklynn
January 2, 2014, 9:43am
2
rs,
ravensiege:
Trying to clean up duplicate content with .htaccess
I’m trying to route the www. to the non www
To route the /index.html to /
Can you help me and see if this .htaccess will work?
Thank You
RewriteEngine On
# Redirect from www to non www
RewriteCond %{HTTP_HOST} ^www\\.site\\.com$ [NC]
RewriteRule ^(.*)$ http://site.com/$1 [L,R=301]
[indent]Yes, that would work but I abhor the use of the :kaioken: EVERYTHING :kaioken: atom so I'd recommend that you replace your RewriteRule with:
RewriteRule .? http://site.com %{REQUEST_URI} [L,R=301]
[/indent]
# Rewrite index.html to root
RewriteRule ^index\\.html$ http://site.com/ [L,R=301]
As for redirecting to your domain, some (few, I believe) installations will force showing the DirectoryIndex. In any event, you need to be sure that the DirectoryIndex is set to index.html (in this case).
You might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It’s helped may members and should help you, too.
Regards,
DK
Thanks DK I appreciate your input.