Rails 新闻过滤 url seo
我想设置
abc.com/news?street=2&area=3$price=6
到
abc.com/news-2-3-6
params街道,区域和价格都是可选的
我的路线喜欢
match "/news(-:street-:area-:price)" => "news#index",:as => :news_index
它效果不好。
I want to set
abc.com/news?street=2&area=3$price=6
to
abc.com/news-2-3-6
the params street,area and price are all optional
My routes likes
match "/news(-:street-:area-:price)" => "news#index",:as => :news_index
It not work well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的路线有两个技术问题,我也会提到一个大问题。
首先,您要添加一个可选段
(-:street-:area-:price)
,这意味着所有术语都必须出现,或者都不出现。如果您希望每个段都是可选的,您需要这样做:其次,您没有指定每个术语可以包含哪些类型的字符。在您的示例中,
news-2-3-6
最终会将:street
设置为“2-3-6”,并保留:area
> 和:price
为空。您需要告诉路由每个变量段接受哪种字符。以下允许每个数字包含 1 个或多个数字:但从长远来看,这些修复都没有帮助。这种“搜索”URL 是一个非常糟糕的主意,因为每个段都依赖于前一个段的存在。我的意思是,如果没有
:area
和:street
就不可能提供:price
,而且也不可能提供没有:price
的:area
。要仅指定:price
,您的 URL 必须类似于/news-0-0-6
。你这样做的理由也从根本上来说是有缺陷的。这不是 SEO。对于 SEO 来说,包含连字符分隔的数字段的 URL 比包含传统查询字符串的 URL 更糟糕。至少传统的查询字符串包含一些可索引术语,例如
street
和price
。There are two technical problems with your route, and one big problem I'll mention as well.
First, you're adding a single optional segment
(-:street-:area-:price)
, meaning either all terms must appear, or none. If you want each segment to be optional, you need to do this:Secondly, you're not specifying which kinds of characters each of the terms can contain. In your example,
news-2-3-6
will wind up setting:street
to "2-3-6", and leaving:area
and:price
empty. You need to tell the route which kinds of characters to accept for each variable segment. The following allows each one to contain 1 or more digits:But neither of these fixes will help in the long run. This kind of "search" URL is a really bad idea because each segment depends on the existence of the previous segment(s). What I mean is, it is impossible to supply a
:price
without:area
and:street
, and impossible to supply a:area
without a:price
. To specify only a:price
, your URL will have to look like/news-0-0-6
.Your reason for doing this is also fundamentally flawed. This is not SEO. A URL containing hyphen-separated numeric segments is worse for SEO than a URL containing a traditional query string. At least the traditional query string contains some indexable terms, like
street
andprice
.