PDA

View Full Version : Redirect non-www to www (ie, your_domain.com to www.your_domain.com)



Brian
May 26th, 2009, 07:35 PM
Search engines see www.domain.com and domain.com as two separate sites. Therefore, if each are indexed, you run the risk of having your site penalized as having duplicate content.

Additionally, domain.com and domain.com/index.html would be seen as being separate pages, although they are the same content, and could divide your incoming links.

There is a way to control this, so that the search engines only index what you want.

Here is some code you can place in your .htaccess file to accomplish both of the scenarios above:



<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /(([^/]+/)*)index.html HTTP/
RewriteRule index.html$ http://www.domain.com/$1 [R=301,L]
</IfModule>


This code will make domain.com redirect to www.domain.com
It will also redirect domain.com/index.html and www.domain.com/index.html to www.domain.com