Ruby On Rails 中的 SEO 重定向修复
我犯了一个错误,允许两条不同的路线指向同一个地方。现在我遇到了重复内容的麻烦。
新闻可以通过两种方式查看: http://website.com/posts/321 和 http://website.com/news/this-is-title/321
我想解决这个问题,我的想法是检查用户来自哪个链接。例如,如果有人通过 http://website.com/posts/321 我想重定向访客正确路线: http://website.com/news/this-is-title/第321章
我的第一个想法是在 Post 控制器验证请求 url,然后在 if 语句中决定重定向或仅显示正确的视图。是良好的构想吗?
I've made mistake and allowed two different routes pointing at same place. Now I've got troubles with duplicated content.
News could be viewed in two ways:
http://website.com/posts/321 and http://website.com/news/this-is-title/321
I want to fix this mess and my idea is to check by what link user is coming. For example if someone will came through http://website.com/posts/321 I would like to redirect visitor to correct route: http://website.com/news/this-is-title/321
My very first idea is to validate request url at Post controller and then in if statement decide about redirecting or simply displaying proper view. Is it good conception?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为你不应该打扰,看看规范网址如果您担心 SEO
I don't think you should bother, take a look at canonical url's if you're worried about SEO
在您的
posts_controller.rb
中显示:In your
posts_controller.rb
show:我认为这不是最合适的。
您应该使用重定向方法在路由级别执行此操作。
I think it's not the best fit.
You should do this at routes level using the redirect methods.