How to redirect non-www to www URLs

www-URL
www-URL

Which one should I choose?

Technically www and non-www URLs are different and that it could hurt your SEO if you keep both around.

For example, the domains http://non-prefix.com and http://www.prefix.com are technically different. (note the “www” in one but not the other)

However, if you check on either, they redirect to the same place, which is a good thing. It helps Google and other search engines to only index one and to not split results.

This article will help you how to redirect your non-www URLs to www, or vice-versa, using .htaccess.

You can add the following code to your .htaccess file, if you want to redirect all non-www requests to your site to the www version.

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

This will redirect any requests to http://non-prefix.com and http://www.prefix.com.

There are several benefits from doing that:

  • To avoid duplicate content in Google
  • To avoid the possibility of split page rank  or split link popularity.
  • It’s nicer, and more consistent.