Tuesday, September 25, 2012

Redirecting non-www to www .htaccess

Here I would like to explain about how to redirect non-www website url to www, usually Google treats non-www and www  URLs as two different domains. We recommend to  redirect your website from non-www to www URL. Make sure to redirect all main pages in the website should be redirected to www version to avoid duplicate and canonical issues.

Here is the procedure to overcome this problem, add below code to your .htaccess file.

Replace domain.com and update with your website url in following code.
Redirect non-www to www:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*) http://www.example.com/$1 [R=301,L]
Redirect www to non-www:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*) http://example.com/$1 [R=301,L]

Any  suggestions or questions please feel free to update me through below comment box. Thanks for your visit and valuable comments.

No comments:

Post a Comment

Facebook Likes, Increase FB Likes Free