URL 中有多个问号是否有效?

我今天看到了以下网址:

http://www.sfgate.com/cgi-bin/blogs/inmarin/detail??blogid=122&entry_id=64497

注意查询字符串开头的双倍问号:

??blogid=122&entry_id=64497

我的浏览器似乎没有任何问题,并运行一个快速的书签工具:

javascript:alert(document.location.search);

只是给了我上面显示的查询字符串。

这是一个有效的 URL 吗?我之所以如此迂腐(假设我是这样的)是因为我需要解析像这样的 URL 作为查询参数,并且支持双问号需要对我的代码进行一些修改。显然,如果他们在野外,我将需要支持他们; 我主要是好奇,如果这是我的错没有遵守 URL 标准,或者如果它实际上是一个非标准的 URL。

63712 次浏览

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.

https://www.rfc-editor.org/rfc/rfc3986#section-3.4

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