Choose which version of the domain URL will be used for the website, only one of the following (www or non-www) must be used:

  • www.domainname.tld
  • domainname.tld

Create a proper .htaccess file to 301-redirect all non-canonical versions of your URL to the proper version. This file must be located in the root of your web directory. In the example below change domainname to your domain name and tld to the extension of your domain name.
This example turns all non-www urls into www versions.

RewriteCond %{HTTP_HOST}; .
RewriteCond %{HTTP_HOST}; !^www\.domainname\.tld [NC]
RewriteRule (.*) http://www.domainname.tld/$1 [R=301,L]

Set the preferred (canonical) URL version in Google Webmaster Tools. To do so you will have to confirm ownership of both version of the domain (www and non-www). To do so, follow these instructions:

  1. Log into Google Webmaster Tools
  2. Add a new website if it has not yet been added
  3. Go to the relevant website's dashboard
  4. In the left menu, go to Site configuration >> Settings
  5. In the Preferred URL section set your displayed URL preference (at this point webmaster tools might ask you to confirm ownership of the www and non-www versions), make sure your preference matches your canonical url settings and .htaccess settings!

MODx Revolution

Create the following template variable:

  • Name: canonicalUrl
  • Template access: all
  • Input type: text
  • Default content:

This will create the proper canonical URL based on your configurations. To change site_url value, add it as a context setting.

The home page must have a canonical URL setting of This way of coding the canonical URL is great for URLs containing tags, since these tags won't appear in the canonical version, meaning that all variations of a given page will transfer content to the canonical url of that page. Finally, change the value of the canonicalUrl TV based on the needs of each page.


Canonicalization is the process of transforming all possible representations of your URLs into one (canonical) format. This has many advantages, primarily avoiding backlink dilution between two URLs for the same page and duplicate content issues. It is important to understand that the www part of a URL is technicaly a subdomain of domainname.tld. Using the www is part of web tradition, it is not mandatory, but is widely used for website domains.