我们可以使用 &在网址?

发布于 2024-08-10 07:20:06 字数 53 浏览 2 评论 0原文

我们可以使用“&”吗在网址中?或者应该使用“和”

Can we use "&" in a url ? or should "and" be used?

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

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

发布评论

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

评论(4

孤独陪着我 2024-08-17 07:20:06

是的,您可以在 URL 路径中简单地使用它,如下所示:

http://example.com/Alice&Bob

仅当您想在查询中使用它时,您需要使用 %26 对其进行编码:

http://example.com/?arg=Alice%26Bob

否则在解释时它将被解释为参数分隔符作为 application/x-www-form-urlencoded

有关更多详细信息,请参阅 RFC 3986

Yes, you can use it plain in your URL path like this:

http://example.com/Alice&Bob

Only if you want to use it in the query you need to encode it with %26:

http://example.com/?arg=Alice%26Bob

Otherwise it would be interpreted as argument separator when interpreted as application/x-www-form-urlencoded.

See RFC 3986 for more details.

情仇皆在手 2024-08-17 07:20:06

URL 通常采用以下形式

scheme://host/some/path/to/file?query1=value&query2=value

So 不建议在 URL 中使用它,除非您想将其用作参数。否则,您应该使用 %26 对它进行百分比转义,例如,

http://www.example.com/hello%26world

这会导致路径被提交为 hello&world。还有一些其他字符在 URL 中脱离上下文使用时必须转义。请参阅此处查看列表。

An URL is generally in the form

scheme://host/some/path/to/file?query1=value&query2=value

So it is not advisable to use it in an URL unless you want to use it for parameters. Otherwise you should percent escape it using %26, e.g.

http://www.example.com/hello%26world

This results in the path being submitted as hello&world. There are other characters which must be escaped when used out of context in an URL. See here for a list.

甜扑 2024-08-17 07:20:06

除非您将变量附加到查询字符串,否则对其进行编码。

Unless you're appending variables to the query string, encode it.

就像说晚安 2024-08-17 07:20:06

对“&”进行编码与 & (此答案基于您对标签的使用)

如果您询问如何使用“&”或“和” 当注册您的 URL 名称时,我会使用“和”。

编辑:正如评论中提到的“& 是一个 HTML 字符实体,而不是 URI 字符实体。通过将其放入 URI,您仍然拥有 & 字符和其他无关字符。”我在完全理解你的问题之前就开始回答了。

encode '&' with & (this answer is based on your use of tags)

If you are asking what to use "&" or "and" when registering the name of your URL, I would use "and".

EDIT: As mentioned in comments "& is an HTML character entity and not a URI character entity. By putting that into a URI you still have the ampersand character and additional extraneous characters." I started answering before fully understanding your question.

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