Ruby on Rails 301 重定向 [英] Ruby on Rails 301 redirection
问题描述
我在某些模型中添加了 slug,但由于 SEO,我需要从旧链接进行 301 重定向:旧:
I added slugs to some of the models, but because of SEO I need to do 301 redirection from old links: old:
http://host.com/foo/1
新:
http://host.com/foo/foo_slug
问题:在这种情况下如何实现301重定向?是否可以从大写链接实现 301 重定向?像这样:
question: how to implement 301 redirection in this case? and is it possible to implement 301 redirection from uppercased link? Like this:
http://host.com/foo/FOO_SLUG -> http://host.com/foo/foo_slug
推荐答案
您应该能够通过将其添加到您的控制器操作来重定向状态 301:
You should be able to redirect with status 301 by adding this to your controller action:
redirect_to "http://host.com/foo/foo_slug", :status => 301
请参阅 redirect_to
的 API 文档,了解详情.
See the API documentation for redirect_to
for details.
并且将大写 URL 重定向到小写版本应该没有问题,尽管这可能由 HTTP 服务器层的某些东西更好地处理,例如 Apache mod_rewrite 规则.
And there should be no problem with redirecting upper-cased URLs to lowercased versions, although this may be better handled by something at the HTTP server layer such as Apache mod_rewrite rules.
这篇关于Ruby on Rails 301 重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!