将许多 URL 参数重写为更“可读”的格式
上下文:具有许多(可选)搜索参数的事件系统。虽然这在一定程度上是一个用户体验问题,但我觉得这仍然属于 SO。
一个简单的 URL 可能看起来像:
example.com/events?date=X-Y-Z&type=race&location=Lapland
以及建议的“更易读”格式:
example.com/events/location:lapland|type:race|date:X-Y-Z
您认为后者并不比前者更具可读性吗?或者“重新发明”查询语法的权衡不值得?或者也许是另一个语法建议?
注意:我偏离了典型的重写events/{location}/{type}/{date}
,因为这些都是可选的查询过滤器,并且有没有明显的方式将值映射到其相关参数。
Context: An events system with many (optional) search parameters. Whilst this is partly a UX question, I feel this still belongs on SO.
A plain URL might look like:
example.com/events?date=X-Y-Z&type=race&location=Lapland
And the proposed 'more readable' format:
example.com/events/location:lapland|type:race|date:X-Y-Z
Would you argue that the latter is no more readable than the former? Or that the trade-off for having 'reinvented' the query syntax isn't worth it? Or perhaps another syntax suggestion?
NB: I've strayed from the typical rewrite events/{location}/{type}/{date}
, since these are all optional query filters, and there'd be no discernible way to map values to their associated parameter.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如何使用 : 和 |超过=和&有什么改进吗?某些 CMS(例如 Wordpress)发出的“可读”URL 的好处是它们不包含任何变量名称,而是使用每个帖子标签,例如
example.com/ Tags/lapland
、example.com/tags/race/
、example.com/2011/12/13/
,尽管我不记得任何语法对于 AND 标签,最有意义将是一个空格,如example.com/tags/lapland race
中所示。因为这将是 x-www-urlencoded 加上一个加号example.com/tags/lapland+race
(有些浏览器会显示一个空格,有些浏览器会显示 urlencoded 形式),你会得到一个很好的助记符 (x+ y.. x 和 y,有点)。Just how is using : and | over = and & any improvement? The gain of "readable" URLs as emitted by certain CMSes (like Wordpress) is that they do not contain any variable names, and work with per-post tags instead, e.g.
example.com/tags/lapland
,example.com/tags/race/
,example.com/2011/12/13/
, and though I have not remembered any syntax for ANDing tags, the most meaningful would be a space, as inexample.com/tags/lapland race
. As that will be x-www-urlencoded with a plus asexample.com/tags/lapland+race
(some browsers will display a space, some the urlencoded form) you get a good mnemonic (x+y.. x and y, sort of).