Provide valid 301 redirects using Rails routes.rb

I recently needed to handle some URL changes in a Rails application, basically modifying an existing route to point somewhere else. I wanted to make sure that the old route still existed so that users who might rely on it would not get left behind, not to mention search indexes that might have picked up the old location. I used the method outlined by Andrew Bruce, then tweaked it to make sure that params that were being passed by the user remained intact.

Basically you can follow his technique and use the code below in the controller.

Pretty simple, and very effective when you need to move things around but still provide access to the deprecated URLs.