How to do IP/URL Canonicalization via .htaceess?

What is IP and URL  Canonicalization and why it is important for SEO?

It is quite important to understand Canonicalization. Probably the term is very difficult to pronounce, but it is one of the most important terms in the world of SEO. Canonicalization refers to how a website can use different URLs and/or IP's for the same piece of content (usually the entire web page). For example; every website resolve to a particular IP address of the hosting machine.

“Canonicalization is the process of picking the best url when there are several choices, and it usually refers to home pages. For example, most people would consider these the same urls:

http://www.cfts.co
http://cfts.co
https://www.cfts.co
https://cfts.co

But technically all of these urls are different. A web server could return completely different content for all the urls above. When Google “canonicalizes” a url, we try to pick the url that seems like the best representative from that set.

This behaviour is not search engine friendly, because the spiders are unsure as which URL is the correct one (If I put it right, which page is a Canonical one among the set of pages with same contents). The search engines don’t like duplicate contents and so URL and to a musch lesser extent IP canonicalization is very important in SEO point of view.

Here’s what Google says about Canonical Page:

A canonical page is the preferred version of a set of pages with highly similar content.

There are 2 types of Canonicalization the most common URL and the other IP, let's take our domain as an example

  1. URL http://cfts.co and http://www.cfts.co get redirected to https://cfts.co
  2. IP 212.38.189.64 gets redirected to https://cfts.co also. (do not do this if you're on a shared IP)

How to configure IP canonicalization in Apache Web server?

The problems with IP Canonicalization can be fixed using the mod_rewrite module and .htaccess. If your website is running on an Apache web server, then you can copy the below lines and paste into the appropriate place in the  .htaccess file located in website’s root directory.

IP Canonicalization has more to do with server side configuration – although, we can sort this out with a 301 redirect.

IP Canonicalization -- BEGIN
RewriteCond %{HTTP_HOST} ^212\.38\.189\.64
RewriteRule (.*) https://cfts.co/$1 [R=301,L]
##### IP Canonicalization -- END

*There is no guarantee that IP canonicalization will improve a site's search engine ranking.

Remove the www prefix and redirect to https

To ensure that all URLs of a given domain present without the www prefix, open the domain’s root .htaccess file and add the following chunk of code:

IP Canonicalization -- BEGIN
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^cfts\.co$ [NC]
RewriteRule ^(.*)$ https://cfts.co/$1 [R=301,L]
##### IP Canonicalization -- END

Some control panels like ours will just allow you to make the URL or Domain redirects without having to mess with systems files directly.

For strong SEO, IP Canonicalization you should use 301 redirect and become sure that the IP does not get indexed.

This tells Google, Bing, Yahoo! and all other Search engine crawlers that the current page should be treated as though it were a copy of the URL https://cfts.co and that all of the links & contents should technically flow back to said URL and don’t mark the URL https://cfts.co page content as a duplicate.

on Monday May 27 by Peter Atkin
Was this helpful?