SEO

How do I redirect non www url to the www url?

This is a great method to get your website indexed correctly by search engine spiders. Many search engine spiders consider domain.com and www.domain.com to be separate and get indexed separately. This can create Pagerank and duplicate content issues, if your links are spread out between domain.com and www.domain.com your site will show a lower Pagerank value than it really is. You’ll also risk the chance at search engines thinking you have duplicate content, and in search engine optimization terms this is bad thing.

Add the below code into you .htaccess file to redirect your non-www url to your www url. You need to change yourdomain.com to your websites domain name.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^yourdomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]

If you want to redirect your www url to your non-www version then instead use the below code and insert it into your .htaccess file.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.yourdomain\.com$ [NC]
RewriteRule ^(.*)$ http://yourdomain.com/$1 [R=301,L]