美元符号$在URL中有什么作用?

37

我一直在阅读关于$ ! ; . ,是URL中“保留”字符的文章。但我找不到它们被保留的原因。

我已经阅读到$ ! ; . ,这些字符在url中被“保留”。但是我无法找到它们被保留的原因。

/ path delimiter  
: port
? query  
& glue get params  
= param=val  
\# link anchor  
+ space

我的具体问题:
有人知道 $ ! ; . , 有什么用吗?
请求 URI 中的 : 是否有特殊含义?


我认为这个问题太宽泛了,不是一个具体的编程问题。它可能更适合于[programmers.se]或[webmasters.se]。 - Kermit
2个回答

38

RFC 2396已经过时。

有关规范的现代版本,请参见:

关于 /

是的,它用作路径部分的分隔符。

关于 :

是的,它用作端口的前缀,但它还有其他角色,比如用户信息分隔符,以及主机指示符的IP样式的分隔符。

关于 =

令人惊讶的是,=字符不是URL、URI或IRI语法的一部分。它只在http(s)协议中具有特殊含义。这与URL/IRI/URI无关。

关于 +

+作为空格的替代符号不是URL/URI/IRI语法的一部分。它只是一些PHP程序为了获得漂亮的URL而方便地发明的。

关于 $ 和 ;

它们在URL/URI/IRI语法中没有特殊含义。它们可以是子定界符生成式的一部分,可以在用户信息部分、未来IP部分、路径段或主机部分中使用。


2
非常棒的答案。如果可以的话,在请求URI中添加一些关于$、;、.、和:的内容。 - CoR
“=”怎么不是通用URL语法的一部分呢?google.com/search?q=test - Kermit
@FreshPrinceOfSO:自己去查一下规范。 - Sean B. Durkin
@FreshPrinceOfSO 这种编码源自于HTML的application/x-www-form-urlencoded编码 - Gumbo
确实,在某些实现中,x-www-form-urlencoded 将 ';' 解释为与 '&' 等效-请参见 https://dev59.com/X3E95IYBdhLWcg3wUMLW#7287629。 - Royce Williams
自从RFC3986以来,=是子分隔符的一部分,+也是。 - John Smith

4
您的问题有些宽泛,但RFC 2396应该包含了您所有的答案。

Many URI include components consisting of or delimited by, certain special characters. These characters are called "reserved", since their usage within the URI component is limited to their reserved purpose. If the data for a URI component would conflict with the reserved purpose, then the conflicting data must be escaped before forming the URI.

 reserved    = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
                "$" | ","

The "reserved" syntax class above refers to those characters that are allowed within a URI, but which may not be allowed within a particular component of the generic URI syntax; they are used as delimiters of the components described in Section 3.

Characters in the "reserved" set are not reserved in all contexts. The set of characters actually reserved within any given URI component is defined by that component. In general, a character is reserved if the semantics of the URI changes if the character is replaced with its escaped US-ASCII encoding.


5
好的,但是$ ; . ,这些符号有什么用? - CoR
2
它们可以用于特定应用功能。仅因为它们是“保留”的并不意味着它们不能被使用。 - Kermit
按照这种逻辑,冒号:也有免费/特定应用程序的功能,对吧?当然,如果它用在请求URI中 :) - CoR
3
RFC 3986 解释了 $ ; , 可以作为 URL 标识符中的子分隔符。 - Kermit

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接