Url htaccess Rewrite: Solve Canonicalization Using .htaccess File

In this post I am going to discuss about the most important issue of canonicalization and the way to tackle it using .htaccess file. I have also explained how to redirect website URLs using cPAnel, IIS7 and nginx. The code for every method is provided below and hence making it a very easy task to avoid duplicate content issue.

Canonicalization is one of the most complicated and confusing query among the webmasters. Canonicalization is the issue which arises due to the presence of the same content on WWW and non-WWW version of the website. At the current time the Search Engine crawlers are not advanced enough to distinguish between two versions of a website URL and hence treat both URLs as different identity with the same content. This situation leads to the problem of ‘Duplicate Content’ and we all know what Google says about it! There are many ways to solve canonical issues and I had discussed the  most notable ones in the below section.

Let’s take an example; suppose my website’s Home page can be opened by different URLs like

In this situation; the all URLs will directs to the home page of the website but Google and many more other search engines will treat it as different web pages having same URL and hence can penalize the website. If you too are encountering the situation where even after adopting every white hat SEO technique, your website is showing poor rank in SERP; Canonicalization may be the issue. To bundle up all the complications; you have to fix canonical issue.

Google’s official speaker Matt Cutt’s view about canonicalization

The solution to deal with this serious issue is to designate 301 URL redirection with .htaccess file. The .htaccess is actually a configuration file compatible with web servers running the Apache Web Server software. This file is read by the Apache web server software and can be used for many purposes.

301 redirection with .htaccess file

  • Open a new notepad document and save the file with the name of .htaccess.
  • Now paste the below provided code in the file. Replace DOMAINNAME with your website domain and index.html need to replace by your home page file name. After configuring the code; upload this file on your server using FTTP software.

Redirect Using cPanel

For the users whose web hosting service provides cPanel can redirect the pages without using any code. To redirect using cPanel; Login to cPanel => Go to Redirects and follow the guidelines of the snapshot.

Redirect WWW to non-WWW

WWW to non WWW cpanel

Redirect non-WWW to WWW

non WWW to WWW cPanel

Redirect Using IIS7

If you want to redirect using IIS7 then add the below provided code as the first rule in the “system.webserver” section of the “web.config”.

Redirect WWW to non-WWW:

Redirect non-WWW to WWW

Redirect Using nginx

Nginx is one of the most popular servers at the present time. For nginx user the code for redirecting the URL is provided in the below section. Add this code at the top of your website Configuration file.

Redirect WWW to non-WWW

Conclusion

I hope that you would have successfully redirected your website URLs to solve canonicalization issue. Finding any query? Share that with me in the comment section below. I will like to hear your feedback about my post.

Keep Tracking Webgranth: Keep Loving Web Technology

 

Jennifer Adam

The area of interest of Jennifer Adam is to cater technologically advanced and powerful tool which works remarkably with multiple browsers and devices. Being a talented professional of inkyROBO, she is capable of implementing the innovative ideas and also loves to write inspiration blogs.