This is very essential for webmasters, to avoid the search engines’ duplicate penalty. It will also make your links look better.
Simply, Google and other search engines would consider the two following domains a duplicate of each other and apply a ‘duplicate content penalty’:
Duplicate penalty:
This penalty is applied by Google and possibly other search engines when content found on your website is largely the same as what is found elsewhere on your site or on other websites across the internet.
The penalty applied is lowering the page rank of both websites; this means not showing on top of the search results.
Choose one of the domains:
You can either force the ‘www’ to exist if the user doesn’t type it as a part of the URL, or you can force remove it even if your visitor typed it in the address bar. it can work either way as long as you choose to apply one of the two cases.
For me, I like to remove the ‘www’ .. I believe it looks better, but you can choose whatever suits you better. The idea is to permanently redirect the visitors to whatever domain name you choose, and since the APACHE servers are the most widely used web-server, I will be discussing applying the permanent redirect through the .htaccess file.
The code:
# this is to go in the .htaccess in the root of the web_directory
RewriteEngine On
rewritecond %{http_host} ^www.example.com$ [nc]
rewriterule ^(.*)$ http://example.com/$1 [r=301,nc]
Copy the previous code, and paste it in the .htacess file located in root directory for the website where you hosting your files.
Do not forget to use your own domain instead of “example.com” in my code.
What this actually do:
This will tell both the browsers, and the search engines, that the website (that starts with ‘www’) has been permanently moved to the other domain (in this case, the one without the ‘www’).
Hint:
You can alter the code to enforce the existence of the ‘www’ in the URL. try it and post in the comments if you need any help.