Ruby on Rails 301 Redirection

I added bullets to some models, but due to SEO I need to do 301 redirects from old links: old:

http://host.com/foo/1

new

http://host.com/foo/foo_slug

Question: how to implement 301 redirects in this case? and is it possible to implement 301 redirects from the top link? Like this:

http://host.com/foo/FOO_SLUG -> http://host.com/foo/foo_slug
+5
source share
2 answers

You should be able to redirect with 301 status by adding this to your controller action:

redirect_to "http://host.com/foo/foo_slug", :status => 301

See the API documentation for details redirect_to.

And there should be no problem redirecting the upper-window URL to lower versions, although this can be better handled by something at the HTTP server level, such as Apache mod_rewrite .

+13
source

301 :

[ "Status" ] = "301 Moved Permanentently"

redirect_to " http://host.com/foo/foo_slug" #

, capize down case, URL- .

ruby, URL

+2

All Articles