Agile Web Development

Build it. Launch it. Love it.

seo_urls

Installation:

script/plugin install http://svn.redshiftmedia.com/svn/plugins/seo_urls

Usage:

To apply this plugin to a model:

class Post < ActiveRecord::Base

   seo_urls

end

Or to use an attribute other than name or title:

class Post < ActiveRecord::Base

   seo_urls "nickname"

end

Information

The plugin looks for ‘name’ or ‘title’ attributes and if they are available it uses them to generate a search engine friendly string. to_param method is overwritten so that it returns the the numerical id of the record with the search engine friendly string appended to it.

An example model @post=>{:id=>12,:title=>"seo_urls rails plugin"}

Without the plugin: post_url(@post)=>"/posts/show/12"

With the plugin: post_url(@post)=>"/posts/show/12-seo-urls-rails-plugin"

If the value of the attribute being used to create the url string for a particular model changes, so will the resulting url string. However, old urls (which might have been stored in bookmarks etc.) will still work because rails only pays attention to the id reference number that begins the :id portion of any url, ignoring anything that follows it.

Resources

Subversion

Author

  • Tomasz Kaye. info [at] redshiftmedia [dot] com

Vitals

Home http://www.bitbutter.com/seo_urls-plugin-making-show-pages-more-findable/14
Repository http://svn.redshiftmedia.com/svn/plugins/seo_urls
License Rails' (MIT)
Tags Tag_red id model permalink seo to_param url
Rating (5 votes)
Owner Redshift Media
Created 22 July 2007

Comments

  • Redshiftmedia
    23 July 2007

    At the time of writing the short install command isn't working, so please use:

    script/plugin install http://svn.redshiftmedia.com/svn/plugins/seo_urls

  • Avatar
    chris
    26 July 2007

    Cool.

    I rearranged the else statement to allow a function to be used as well to generate the name if the passed string isn't an attribute...

    elsif self.respond_to? attribute_for_url.to_sym

            string=self.send(attribute_for_url)
    
  • chris
    21 April 2008

    FYI: This plugin can result in multiple URLs pointing to the same content such that there's no single permalink. This situation can be bad for SEO.

    I suggest that your controller should check the url used for inbound access and send a 301 redirect if it's not the current one.

    Also, SEO is better if you don't have an ID at the front of the URL, I recommend acts_as_url_param if you're looking for the best SEO possible.

Add a comment