Is it valid to have more than one question mark in a URL?

两盒软妹~` 提交于 2019-11-26 16:24:34

Yes, it is valid. Only the first ? in a URL has significance, any after it are treated as literal question marks:

The query component is indicated by the first question mark ("?") character and terminated by a number sign ("#") character or by the end of the URI.

...

The characters slash ("/") and question mark ("?") may represent data within the query component. Beware that some older, erroneous implementations may not handle such data correctly when it is used as the base URI for relative references (Section 5.1), apparently because they fail to distinguish query data from path data when looking for hierarchical separators. However, as query components are often used to carry identifying information in the form of "key=value" pairs and one frequently used value is a reference to another URI, it is sometimes better for usability to avoid percent-encoding those characters.

http://tools.ietf.org/html/rfc3986#section-3.4

As a tangentially related answer, foo?spam=1?&eggs=3 gives the parameter spam the value 1?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!