url参数命名约定或遵循的标准是什么

发布于 2024-07-14 02:49:57 字数 172 浏览 3 评论 0原文

Url 参数是否有任何命名约定或标准需要遵循。 我通常使用驼峰式大小写,例如 userIditemNumber。 当我即将开始一个新项目时,我正在寻找是否有任何东西可以做,但找不到任何东西。 我不是从语言或框架的角度来看待这个问题,而是更多地将其视为通用的网络标准。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

二货你真萌 2024-07-21 02:49:57

我建议阅读 Tim Berners-Lee 撰写的 Cool URI's Don't Change 来深入了解这一点问题。 如果您在 URI 中使用参数,最好重写它们以反映数据的实际含义。

因此,与其具有以下内容,

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

不如

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

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

/index.jsp?isbn=1234567890

/index.aspx?isbn=1234567890

意味着您网站上的所有链接现在都已损坏。

一般来说,只有当用户可以合理地期望生成他们正在检索的数据时(例如通过搜索),您才应该使用查询字符串。 如果您使用查询字符串从数据库中检索不变的资源,请使用 URL 重写。

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

You'd have

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

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

becomes

/index.aspx?isbn=1234567890

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

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.

百变从容 2024-07-21 02:49:57

URI 标准由 RFC2396 定义。
URL 标准化部分之后的任何内容都留给您。

您可能只想根据您使用的框架遵循特定的参数约定。
大多数时候,您甚至不会真正关心,因为这些不在您的控制之下,但是当它们在您的控制之下时,您可能希望至少保持一致并尝试生成用户友好的位:

  • ,那么它们很短
  • 如果它们旨在的话 可供用户直接访问,它们应该易于记忆,
  • 不区分大小写(可能很难,具体取决于服务器操作系统)。
  • 遵循一些SEO 指南和最佳实践,它们可能会帮助您很多。

我想说,在呈现 URL 时,清洁度和用户友好性是值得努力的目标。
StackOverflow 在这方面做得相当好。

Standard for URI are defined by RFC2396.
Anything after the standardized portion of the URL is left to you.

You probably only want to follow a particular convention on your parameters based on the framework you use.
Most of the time you wouldn't even really care because these are not under your control, but when they are, you probably want to at least be consistent and try to generate user-friendly bits:

  • that are short,
  • if they are meant to be directly accessible by users, they should be easy to remember,
  • case-insensitive (may be hard depending on the server OS).
  • follow some SEO guidelines and best practices, they may help you a lot.

I would say that cleanliness and user-friendliness are laudable goals to strive for when presenting URLs.
StackOverflow does a fairly good job of it.

假扮的天使 2024-07-21 02:49:57

据我所知,没有任何标准。 请注意 IE 的URL 长度限制为 2,083 个字符。

There are no standards that I'm aware of. Just be mindful of IE's URL length limit of 2,083 characters.

脱离于你 2024-07-21 02:49:57

我用小写。 根据您使用的技术,QS 可能会受到区分大小写(例如 PHP)或不区分大小写(例如 ASP)的威胁。 使用小写可以避免可能的混淆。

I use lowercase. Depending on the technology you use, QS is either threated as case-sensitive (eg. PHP) or not (eg. ASP). Using lowercase avoids possible confusion.

像你 2024-07-21 02:49:57

就像其他答案一样,我没有听说过任何约定。

我会遵守的唯一“标准”是使用对搜索引擎更友好的做法,即使用 URL 重写器。

Like the other answers I've not heard about any conventions.

The only "standard" I would adhere to is to use the more search engine friendly practice of using a URL rewriter.

迷路的信 2024-07-21 02:49:57

据我所知,没有标准,大小写也不重要。

然而,在您的应用程序(网站)中,您应该坚持自己的标准。 不为别的,为了你自己的理智。

There are no standards that I know of, and case shouldn't matter.

However within your application (website), you should stick to your own standards. For your own sanity if nothing else.

冷血 2024-07-21 02:49:57

尽管可能没有既定的标准或权威,但为了给出一些答案,Google 经常使用驼峰命名法作为查询参数。

参考示例:https://cloud.google.com/apis/docs/system-parameters

Though there may not be an established standard or authority, to give some answer, Google frequently uses camelCase for query params.

Example Reference: https://cloud.google.com/apis/docs/system-parameters

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文