Ruby on Rails and Canonical link tag

August 20th, 2009 at 6:54 pm • permalink0 comments

On February Google, Yahoo, and Microsoft announced support for a new link element to clean up duplicate URLs on sites. The element is called Canonical Link tag and the syntax is pretty simple.

This tag, added in the HEAD section of an HTML page, tells search engines that the preferred location for the content of the request page is the value of the href attribute, in this case http://example.com/page. If you want to learn more about the canonical link tag, have a look at Matt Cutt’s introductory post or Google Webmaster Central.

The new version of my Helperful Rails plugin provides a new method named canonical_link_tag, a super simple helper to generate the canonical link tag. The usage is similar to the auto_complete_link_tag helper.

canonical_link_tag
# => <link rel="canonical" href=http://www.currenthost.com/controller/action" />

canonical_link_tag(:action => "show")
# => <link rel="canonical" href=http://www.currenthost.com/controller/show" />

canonical_link_tag("http://www.example.com/product.php?item=swedish-fish")
# => <link rel="canonical" href="http://www.example.com/product.php?item=swedish-fish" />

You can install or upgrade Helperful via RubyGems.

$ gem install weppos-helperful --source http://gems.github.com
  1. Helperful: a large collection of Rails Helpers
  2. Helperful 0.3.0
  3. TabsOnRails: creating and managing Tabs with Ruby on Rails
  4. Upgrading Rails 2 application to Rails 3 (screencast)
  5. BreadcrumbOnRails now open-source

Filed in Programming, Search Engines • Tags: , , , , ,

Add a Comment




Follow Me
    Random Quote