Putting your sites’ URLs in order with redirects.
Many webmasters are getting in trouble with web hosts that suppose two different pages creation for www.yoursite.com and yoursite.com. Of course you can create a copy of index page and put it in both folders, but such an action can force Google to filter you for duplicate content. It is sometimes very hard, expansive and just senseless or even unfavorably to change web host, so what should you do?
The easiest way to get rid of such a problem is to redirect all instances of your domain name typed by surfers and requested by spiders to single, unified URL with help of some changes in .htaccess file of your web server. This is true for apache, but, for instance in IIS it is performed using ISAPI filter in the same lines.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yoursite\.com$ [NC]
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [R=301,L]
The first line “RewriteEngine On” tells Apache to enable Mod_rewrite - the engine responsible for manipulating URLs.
The first line tells Apache web server to enable mod_rewrite engine, which is responsible for URLs manipulation.
The second line is watching for surfers, who type in yoursite.com without www, while the [NC] flag converts URL in case-insensitive, so it is catching surfers typing YourSite.com.
The third line redirects surfers typing all instances of yoursite.com to www.yoursite.com with help of 301 redirect.
Filed under: HTML and Page Coding