Search engine optimization is a complex field.

However, if you want your website to have any chance of outranking your competitors in SERP, you must have a good SEO knowledge and always keep up the pace with the frequent changes.

Today, I'm going to teach you how to use canonical URL tag and how to perform a domain canonicalization correctly.

One of the most overlooked SEO aspects is URL canonicalization. Many experts concentrate too much on teaching about link building, content optimization, and other SEO aspects, but they often forget to teach the basic, but critical points like URL canonicalization.

First of all, it's essential to understand what a canonical URL is and how to do a correct domain canonicalization if you don't want to risk a penalty from the search engines.

What is URL canonicalization?

URL canonicalization refers to the process of informing the search engines that two or more URLs are in fact the same.


One of my blog posts has the following URL.

Version 1:

Version 2:

A dynamic software like WordPress might also generate the following URL to enable the threaded comments feature.

If I link to the URL version 2 somewhere, the search engines will see that as an entirely different page, even though it's, in fact, the same page as version 1.

From the SEO perspective, that's very bad.

If multiple pages of our websites have the same content, the search engines might penalize us for duplicate content.

Fortunately, there's a quick solution to this problem, and that's the canonical URL tag.

When we implement this tag correctly, we can tell the search engines that those both URLs belong to the same page and they should only index the base URL.

That's an example at the single page level, but the search engines can even see our entire site as a duplicate if we don't use the canonicalization correctly. I'm going to cover these two cases separately and teach you how to fix these issues below.

Domain Canonicalization

Most of the times, websites are accessible either with "www" before the domain name or without "www".

Both of these versions will take you to the same pages and will not greatly influence the browsing experience of the visitors.

Yet, the search engines see the things from a different perspective.

The search engines will perceive the www version and the non-www version as two completely different versions of your website. That's again very bad and your site is susceptible to receive an SEO penalty.


Search engines see the following URLs as being two different pages.


Even if you only add a trailing slash ("/") after the domain name, that's seen as a different version by the search engines.

The things get even more complicated when you have an SSL certificate installed for your domain name and your site becomes now accessible by more versions.

Without the proper redirects in place, your website can be accessed by many versions and that's definitely not good.

The search engines won't know which version of your content to index and everything might lead to a big penalty or poor rankings. Also, if your site's backlinks are pointing to multiple versions of your site, that will create a big chaos.

HTTP domain canonicalization

To fix this problem at domain's level, you don't have to use the rel="canonical" tag. Instead, you must apply a 301 permanent redirect from the www version to the non-www version of your domain name, or vice versa.

A 301 redirect will redirect all the traffic from one version of your site to the preferred version, and because the redirect it's a 301 type, that will also notify the search engines that the URL of your site has changed permanently.

Choosing the www or the non-www version of your domain name it's more a personal preference. From the SEO point of view, there are no advantages to using one or the other.

HTTPS domain canonicalization

If you've also installed an SSL certificate, you should then also redirect your favorite http:// version to the preferred https:// version of your site.

In this case, first, redirect the HTTP traffic to the www or non-www version.

Next, redirect the HTTPS traffic to the www or non-www version.

At this step, your site will be both accessible via HTTP and HTTPS.

Finally, place a redirection from your favorite HTTP version to your preferred HTTPS variant so your domain name will only use the secure version.

How to do a 301 redirect

The steps for setting a 301 redirect differs based on your content management system, or on your server type if you don't use a CMS.

301 Redirect for WordPress

If you use a content management system like WordPress, this task is simpler.

By default, WordPress redirects the www to non-www or vice versa, based on the URLs provided under Settings-->General. Therefore, you don't have to do anything else.

If you have an SSL certificate installed and your site is accessible via HTTPS, then you also need a plugin like Realy Simple SSL to redirect all the URLs to the preferred version.

301 Redirect on Apache

If you don't use a content management system for your site, you'll have to make these redirects manually.

If your site is hosted on Apache server, you have to add the code for the 301 redirect in the .htaccess file found in the root directory of your website.

If there's no .htaccess file, you need to create one. However, for this to work, you have to make sure that the PHP mod_rewrite module is enabled. If not, you have to enable it.

301 Redirect on Nginx

If your site is hosted on Nginx server, you'll have to do the redirection from the Nginx.conf file.

To do that, you'll first have to log in to your server with a SSH client like PuTTY, find the location of the config file (these will depend on several factors) and edit the server{} block that contains the details of your domain name and add the code for a 301 redirect.


server {
    listen 80;
    return 301$request_uri;

The code above should redirect the traffic from HTTP to HTTPS.

Canonical URLs For Pages

Same principle applies to the pages of your website, but there are some additional reasons why some pages can be seen as duplicate.

Dynamically generated pages can add additional filters/variables or user session to the structure of the URL.

I already gave you the example when WordPress adds a "replytocom" variable to enable the threaded comments.

More examples:

An online store might allow users to sort the displayed products by popularity and that feature might generate the following two URLs.

Basically, these pages will display the same content only in a different order.

To tell the search engines that these URLs are the same, we have to add the link rel="canonical" tag between the opening (<head>) and closing (</head>) tags of our page.

The full tag should look like the following:

 <link rel="canonical" href="">

When the code above is present in the HEAD area of a page, the search engines will be notified that all the URL variations found, contain the same content as the base URL "".

This way, the search engines won't try to index the content of every variation as a separate page.

Instead, only "" will be indexed.

WordPress is again smart enough to add these tags automatically to every page of your site.

If you don't use WordPress, you might have to add the canonical tag manually to the HEAD section of all your site's pages.

There are particular situations when even with the canonical tags, the WordPress categories, tags and author archives may have the same content and might be seen as duplicate content by the search engines.

I usually only allow the categories to be indexed by the search engines and set the rest of the archive as "NOINDEX."


Having the canonical URL tag and the correct 301 redirects for the domain name it's very important for SEO if you don't want to have problems with Google and other search engines.

I know that the canonical tag might not be very easy to understand for a beginner and might not be very easy to implement when you don't use a CMS and don't know how to code. However, when you understand its purpose it will make perfect sense.

Leave a Comment