【问题标题】:Rails Routes - Prevent accessing same controller#action through different urls?Rails Routes - 防止通过不同的 url 访问相同的控制器#action?
【发布时间】:2012-02-18 19:28:45
【问题描述】:

我注意到,在 routes.rb 文件中定义路由时,您实际上可以以不同的方式访问您定义的同一个 controller#action。

例如:

map.connect "post/show/:id/:tag_title", :controller => "post", :action => "show", :requirements => {:id => /\d+/}

这意味着您可以访问 post#show 访问

server.com/post/show/1234/tag_title-whatever

但您也可以访问 post#show,前往

server.com/post/show?id=1234&tag_title=tag_title-whatever

这是一个简单的案例,但你明白了。这不会导致搜索引擎出现问题吗?如果我没记错的话,这 2 个网址可能会被视为欺骗页面。

有没有办法防止这种情况发生,比如告诉 Rails 仅按照定义的方式访问定义的路由?

【问题讨论】:

  • 如果路由是 post/:id/show 而不是备用查询字符串方法。

标签: ruby-on-rails routes


【解决方案1】:

能够访问某些内容并不意味着它会被 Google 编入索引。除非另有说明,否则所有 Rails 辅助函数都使用 /post/show/.. 链接。只要您不链接到指定的资源,Google 抓取内容的可能性就很小。

话虽如此,我什至不确定他们是否最终将其编入索引。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多