301 Redirects in Rails

written by Eadz on February 5th, 2007 @ 09:41 AM

A 301 redirect is a permanent redirect, which tells the search engines to index the redirected to URL rather than the current URL.

You can use this when migrating from legacy content management systems, or to make sure that you only have 1 URL per page.

With the folloing code in your controller, Rails makes it easy :

1
2
      headers["Status"] = "301 Moved Permanently"
      redirect_to "http://someurl/"

Like this article? Subscribe to the SEO on Rails feed.

Comments

  • rick on 21 Feb 01:23

    Try this:
    
    head :moved_permanently, :location => 'http://whatever'
    
  • Eadz on 15 Mar 22:14

    Awesome, thanks Rick!

Comments are closed

Options:

Size

Colors