遵循的url参数命名约定或标准是什么 [英] What are the url parameters naming convention or standards to follow

查看:243
本文介绍了遵循的url参数命名约定或标准是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在要遵循的Url参数的命名约定或标准。我通常使用骆驼套,例如 userId itemNumber 。当我要开始一个新项目时,我正在搜索是否有与此相关的任何东西,但找不到任何东西。我不是从语言或框架的角度看待这个问题,而是将其作为一般的Web标准。

Are there any naming conventions or standards for Url parameters to be followed. I generally use camel casing like userId or itemNumber. As I am about to start off a new project, I was searching whether there is anything for this, and could not find anything. I am not looking at this from a perspective of language or framework but more as a general web standard.

推荐答案

我建议阅读<蒂姆·伯纳斯·李(Tim Berners-Lee)的a href = http://www.w3.org/Provider/Style/URI rel = noreferrer>酷URI的不变 ,以深入了解此问题。如果您在URI中使用参数,则最好重写它们以反映数据的实际含义。

I recommend reading Cool URI's Don't Change by Tim Berners-Lee for an insight into this question. If you're using parameters in your URI, it might be better to rewrite them to reflect what the data actually means.

因此,不要使用以下内容:

So instead of having the following:

/index.jsp?isbn=1234567890
/author-details.jsp?isbn=1234567890
/related.jsp?isbn=1234567890

您将拥有

/isbn/1234567890/index
/isbn/1234567890/author-details
/isbn/1234567890/related

它创建了一个更明显的数据结构,这意味着如果您更改平台体系结构,则URI不会更改。没有上述结构,

It creates a more obvious data structure, and means that if you change the platform architecture, your URI's don't change. Without the above structure,

/index.jsp?isbn=1234567890

成为

/index.aspx?isbn=1234567890

这意味着您网站上的所有链接现在都已断开。

which means all the links on your site are now broken.

通常,仅当用户可以合理地期望生成要检索的数据时,才应使用查询字符串。搜索。如果您使用查询字符串从数据库中检索不变的资源,请使用URL重写。

In general, you should only use query strings when the user could reasonably expect the data they're retrieving to be generated, e.g. with a search. If you're using a query string to retrieve an unchanging resource from a database, then use URL-rewriting.

这篇关于遵循的url参数命名约定或标准是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆