The link rel canonical tag lets you solve canonical issues for your URL without having to resort to 301 redirects or other potentially complicated approaches. This article explains how to take advantage of the tag in your PHP-powered web sites.
Any website URL is accessible by either its www or non-www version. For example, if you have a website www.somewebsite.com, people can access it in the browser in two ways:
By typing your canonical www version of the URL into their browser: http://www.somewebsite.com
By typing the non-www version: http://somewebsite.com
If you have SSL (secure socket layer certificate), there are an additional two ways that users can access your web site:
By typing the https www version: https://www.somewebsite.com.
By typing the https non-www version: https://somewebsite.com.
The problem is even trickier if the domain URLs use session IDs, which is very common with e-commerce websites. In addition to helping you with general canonical URL issues, this article will provide solutions for removing session IDs.
Users may not have problems with canonical issues, but what happens to a search engine bot? If sites link to both canonical and non-canonical versions of your website, search engine bots will index several versions of your domain, resulting in duplicate content.
Why is this a serious issue? It will cause the loss and weakening of your internal link juice strength. For example, Google Page Rank flows like water in a pipe, so if some of the link juice flows into the non-canonical version of your domain, it is leaking like water in a pipe with holes.
This is a common problem in search engine optimization and web development. This is a failure on the part of the web development team to create a canonical version of the URL for the site.
The common approach to solving this uses 301 redirects. Now sometimes 301 redirects are difficult for an ordinary webmaster who loves to copy and paste the source code. Worse, this can be implemented using .htaccess, which is prone to server incompatibility issues.
The search engine community, particularly Google, Yahoo and MSN, decided to adopt the link rel canonical element as an easy solution to duplicate content problems, including the non-www and www canonical issue.
This is to be placed in the <head> section of template source code. The objective of this article is to implement this element so that 301 redirection will not be necessary. The scope of this article focuses only on the PHP/Apache website configuration.