Add a Redirect Script to your Ruby on Rails Application

This article will walk you through the process of using a 301 redirect script to your Ruby on Rails application.  The 301 redirect  is a very efficient method of webpage redirection.  More importantly, it is search engine friendly. 

In order to utilize a 301 redirect, you will need to add the following code to a page on your Ruby on Rails application (replacing http://www.domainname.com with the actual desitation URL):

def old_action
headers["Status"] = "301 Moved Permanently"
redirect_to "http://www.domainname.com/"
end

In most cases, you will need to insert this script on a default document such as index.php or default.php in order to redirect a fully-qualified domain name.

NOTE: This script can be inserted in your web root or a sub-directory.