non-www to www redirection with .htaccess

Opening a domain as domain.com or www.domain.com takes to the same page. From the SEO perspective , many suggest that search engines may consider the two to be different sites. So the fix is to apply a redirection to redirect domain.com to www.domain.com

Adding this :

RewriteEngine on
RewriteCond %{http_host} ^yourdomain.com [nc]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [r=301,nc]

to the .htaccess file does the redirection job.

So now opening yourdomain.com will redirect to www.yourdomain.com
which also has a good SEO effect

Popularity: 1% [?]

Leave a Reply