Home arrow PHP arrow Using the Link Rel Canonical Tag

Using the Link Rel Canonical Tag

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.

  1. Using the Link Rel Canonical Tag
  2. Theory of Implementation
  3. Implementation Steps
  4. Implementing a Canonical Version, First Scenario
  5. Implementing Canonical Version for a Secure Website
By: Codex-M
Rating: starstarstarstarstar / 6
May 07, 2009

print this article




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.

<link rel="canonical" href="http://www.yourcanonicalurl.com" />

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.

>>> More PHP Articles          >>> More By Codex-M

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: