Canonical URL’s, Optimized Permalinks


I updated my WordPress permalinks from an old-fashioned and quite outdated /%year%/%monthnum%/%day%/%postname%/ to the more optimized structure /%post_id%-%postname%/. Although I still like it if I can see the date and the entry title at a glance, the new structure has two advantages:

  1. the new permalink structure is in some cases faster because of the way wordpress stores the URL information in the database (see further: Efficient permalink strategies for WordPress)
  2. according to SEO’s, a link like cordobo.com/540-firefox-add-ons-for-developers/ is more likely to result in a better SERP position than (the same) link named cordobo.com/2008/09/30/firefox-add-ons-for-developers/

Migrating old permalinks to a new structure

To avoid duplicate content and 404 – Not found errors, you should redirect visitors and web crawlers (like GoogleBot) to the new URL with the HTTP Status Code 301 – Moved Permanently.

The fastest way to migrate your old permalinks to the new structure is Dean’s Permalinks Migration plugin. It’s from 2006, but it works great with WordPress 2.7.1. After uploading the plugin, activate it and enter your actual permalink structure (the old one), e.g. /%year%/%monthnum%/%day%/%postname%/ on the plugin’s options page and save it. Now you have done that, change the “Permalink Settings” to the new structure, in my case /%post_id%-%postname%/.

Canonical URLs for comments pages

I really like WordPress new way to break comments into various pages, because paginated comments can reduce your traffic and save your visitors browser (or RAM) resources. But on pages with a lot of comments, it can create a lot of duplicate content, like it happened here:

  • http://cordobo.com/224-updateupgrade-to-wp-21/
  • http://cordobo.com/224-updateupgrade-to-wp-21/comment-page-6/
  • http://cordobo.com/224-updateupgrade-to-wp-21/comment-page-5/

A consortium of leading web companies, including Google, Yahoo! and Microsoft, created a new standard to handle this kind of unintended duplicate content – Canonical URLs.

Q: What is a canonical url? Do you have to use such a weird word, anyway?
A: […] 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:

* www.example.com
* example.com/
* www.example.com/index.html
* example.com/home.asp

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.

Quoted from Matt Cutts, SEO advice: url canonicalization

They came up with a simple solution, a reference in the <head> of the page to the preferred URL:
<link rel="canonical" href="http://cordobo.com/224-updateupgrade-to-wp-21/" />

To apply this link automatically to every page with comments, I added some lines of code to the functions.php file of my theme. Steve came up with a simple solution in his article Dealing With Duplicate Content Issues on WordPress Comments Pages:

function canonical_for_comments() {
global $cpage, $post;
if ( $cpage > 1 ) :
echo "\n";
echo "<link rel='canonical' href='";
echo get_permalink( $post->ID );
echo "' />\n";
endif;
}
add_action( 'wp_head', 'canonical_for_comments' );

If you use a plugin like All-In-One-SEO or Yoasts Canonical URL’s for WordPress, you don’t have to worry about it – both already take care about canonical URLs.

If you want to know more about duplicate content and how to avoid it using canonical URLs, watch Matt Cutts video or check the presentation he did at SMX West:


4 responses to “Canonical URL’s, Optimized Permalinks”

  1. I recently changed the structure of my permalinks but I wasn’t aware of Deans plugin and I tried to fix it with htaccess… Many thanks!