Force www vs non-www to avoid duplicate content on Google

Now a Days, it has been talked a lot about Google and duplicate content as well as Google Canonical problems.That is, when you have your site accessible both under and To avoid such problems you can use the following lines in your .htaccess file to force only the www version of your web site:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^(.*)$$1 [R=301]

Please, note that the .htaccess should be located in the web site main folder.

This will redirect all requests to the non-www version of your site to the www version using 301 Permanent redirect which will make the search engines to index your site only using the URL. In this way you will avoid a duplicate content penalty.

Written by 

I am Sakthivel Madesh, a certified Salesforce Advanced Developer & Administrator working on Salesforce Technology since 2011. I am currently working in Techforce Services as Sr. Salesforce Developer. I have worked on multiple technologies Like PHP, Java, Salesforce, I am very passionate about Salesforce and to earn 15x Salesforce Certification. I love Trailhead for learning Salesforce Skill and Become a Trailhead 5x Ranger too. I Love to Learn & Share my Salesforce knowledge to Salesforce Learners/Beginner using My Blog and Salesforce Community.

Leave a Reply

Your email address will not be published. Required fields are marked *