You are here: Browse Railsplugins Redirect Routing
This plugin lets you do simple redirects straight from your routes.rb file:
map.redirect '', :controller => 'events'
This will make the root of your site redirect to the events controller, typically at /events.
You can redirect any URL to any set of options, or event a string URL, like this:
map.redirect 'test', 'http://pinds.com'
GET /test, and you’ll be redirected to my blog.
You can also set the status to be a 301 permanent redirect instead of a temporary 302:
map.redirect 'oldurl', 'newurl', :permament => true
map.redirect 'oldurl', :controller => 'new_controller', :action => 'new_action', :permament => true
Why this plugin?
Because if Rails Routing is supposed to be a Ruby replacement for mod_rewrite, then at least some redirect capability is called for.
But more concretely, because there’s no good alternative unless you’re using Apache. The alternative options that I’ve been able to figure out are:
If there’s demand, I’ll add a switch for a permanent redirect, but I don’t have the need yet.
If you know of a simpler way to do this, please let me know.
Written by Lars Pind
http://pinds.com
NOTE: This description has been extracted from the Plugin README and so the formatting may need updating to make browser friendly