有效的 URL 分隔符

发布于 2024-09-25 21:47:42 字数 1432 浏览 0 评论 0原文

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

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

发布评论

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

评论(5

小ぇ时光︴ 2024-10-02 21:47:42

丹尼斯,我认为你误读了链接文档。该限制仅适用于 URL 的“方案”部分。对于 WWW URL,即“http”。

该文件的下一部分继续说道:

因此,只有字母数字、特殊字符“$-_.+!*'(),”和
可以使用用于其保留目的的保留字符
URL 中未编码。

我个人会使用逗号(,)。然而,加号 (+) 和破折号 (-) 也是合理的选择。

顺便说一句,该文档还提到分号(;)在某些方案中被保留。

Dennis, I think you have misread the linked document. That limitation only applies to the "scheme" portion of the URL. In the case of WWW URLs, that is the "http".

The next section of the document goes on to say:

Thus, only alphanumerics, the special characters "$-_.+!*'(),", and
reserved characters used for their reserved purposes may be used
unencoded within a URL.

I'd personally use comma (,). However, plus (+) and dash (-) are both reasonable options as well.

BTW, that document also mentions that semi-colon (;) is reserved in some schemes.

赴月观长安 2024-10-02 21:47:42

好吧,根据 RFC1738,有效的 URL 只能包含字母 a< /kbd>-z、加号 (+)、句号和连字符 (-)。

一般来说,我会用加号来分隔您的搜索区域。因此,您的网址将变为 http://www.example.com/list?seach_type=0&search_period=1&search_min=3000&search_max=21000&search_area=6855+7470+7700+..

--编辑--

正如 GinoA 指出的,我误读了该文档。因此,“$-_.+!*'(),”在未编码 URL 中也是有效字符。不过,我仍然会使用 + 符号。

Well, according to RFC1738, valid URLs may only contain the letters a-z, the plus sign (+), period and hyphen (-).

Generally I would go with a plus to separate your search areas. So your URL would become http://www.example.com/list?seach_type=0&search_period=1&search_min=3000&search_max=21000&search_area=6855+7470+7700+...

--EDIT--

As GinoA pointed out I misread the document. Hence "$-_.+!*'()," are valid characters too in an unencoded URL. I'd still go with the + sign though.

剩一世无双 2024-10-02 21:47:42

如果只有数字需要分隔,那么您有多种分隔符可供选择。例如,您可以选择任何字母。

也许一个空间是一个不错的选择。它将在 URL 中转换为 + 字符,因此比字母更易读。

示例:search_area=4000+5000+6000

If there are only numbers to separate, you have a large choice of separators. You can choose any letter for example.

Probably a space can be a good choice. It will be transformed into + character in the URL, so will be more readable than a letter.

Example: search_area=4000+5000+6000

你对谁都笑 2024-10-02 21:47:42

我参加聚会很晚了,但是有效的查询字符串可以重复变量,因此

http://x.y.z/list?type=0&period=1&min=3000&max=21000&area=6855+7470+7700

您也可以使用...而不是...

http://x.y.z/list?type=0&period=1&min=3000&max=21000&area=6855&area=7470&area=7700

I'm very late to the party, but a valid query string can repeat variables so instead of...

http://x.y.z/list?type=0&period=1&min=3000&max=21000&area=6855+7470+7700

...you could also use...

http://x.y.z/list?type=0&period=1&min=3000&max=21000&area=6855&area=7470&area=7700
被你宠の有点坏 2024-10-02 21:47:42

当内容类型为 application/x-www-form-urlencoded(HTML 表单的标准)时,“+”将被解释为空格“”。这可能由您的服务器软件处理。

我更喜欢“!”。它不会进行 URL 编码(至少在 Chrome 中不会),并且在典型情况下保留“+”用作真实的空格字符。

"+" is to be interpreted as a space " " when the content-type is application/x-www-form-urlencoded (standard for HTML forms). This may be handled by your server software.

I prefer "!". It doesn't get URL encoded (at least not in Chrome) and it reserves "+" for use as a real space character in the typical case.

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