Resolving a non WWW to WWW or vice versa is considered good practice. Using this resolve may help to avoid duplicate content, and also is more consistent for the user. Adding the following code will redirect users to “www.yourdomain.com” if they were to type “yourdomain.com” into the address bar.

Redirect non WWW to WWW

Add the following code to your .htaccess file to redirect non WWW to WWW.

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

Redirect WWW to non WWW

You may want to do the opposite to that above, add the following code to your .htaccess file to redirect WWW to non WWW. Just remember to replace “yourdomain” with your actual domain.

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