ActionController::Base#redirect_to currently only renders temporary 302 Found responses. In order to render a permanent redirect (301 Moved Permanently), one must manually set the status on the response:
def perm_redirect
response.headers["Status"] = "301 Moved Permanently"
redirect_to :action => "the_real_deal"
end
For such a simple operation, this is super ugly.
This patch allows for the use of the common :status option:
redirect_to book_url(@book), :status => 301
redirect_to "http://www.example.com", :status => :temporary_redirect
redirect_to({ :action => "the_real_deal" }, :status => :permanently_moved)
redirect_to :back, :status => 301 # For consistency's sake; I can't imagine someone using this.
When not specified, redirect_to falls back on the default of using 302 Found.
I think it's important for the framework to have this support baked in because of the importance of 301 redirects in keeping a web site's Google Rank constant. 302 redirects do not transfer the Google Fu, 301 redirects do.
Judging by the sheer number of blog entries and mailing list hits, I think there's a pretty strong demand for this functionality <http://www.google.com/search?q=rails%20redirect_to%20301>.
This patch includes full unit tests, and passes existing unit tests.