【问题标题】:SEO-friendly URL design for filtering a resource in Rails 3用于在 Rails 3 中过滤资源的 SEO 友好 URL 设计
【发布时间】:2011-05-04 08:10:18
【问题描述】:

我需要为 Rails 3 中的资源实现一些对 SEO 友好的排序方法。这是我正在考虑为集合做的事情:

/things                  # shows all things
/things/popular          # shows all things ordered by popularity
/things/a-z              # shows all things ordered alphabetically

这对于单个记录:

/thing/name-of-a-thing   # shows ONE thing

单数/复数之间的切换是为了避免thing-namessort-method-names发生冲突。

到目前为止,我一直在使用resource :things,它使用/things 进行所有操作。我很担心要摆脱默认设置,因为我知道在设置这些默认设置方面已经考虑了很多。所以在我这样做之前,我想我会寻求一些建议,以防这种事情有最佳实践。

那么,这是解决我问题的好方法吗?我是否对未来的任何问题敞开心扉?有没有更好的方法来解决这个问题?

谢谢!

【问题讨论】:

    标签: ruby-on-rails url rest routing information-architecture


    【解决方案1】:

    您需要通过匹配定义所有路由。

    match '/things' => 'Things#index'
    match '/things/:order' => 'Things#index'
    match '/thing/:id' => 'Things#show'
    

    在所有匹配路由定义后杀死你的资源、路由或使用它。

    【讨论】:

    • 谢谢,但这不是问题所在。我了解如何实现这一点。我在问这是否是一个好的 URL 设计和/或有什么替代方案/最佳实践来解决这个问题。
    猜你喜欢
    • 2011-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-08
    • 1970-01-01
    • 2011-08-25
    • 1970-01-01
    相关资源
    最近更新 更多