0

今天我们和同事争论这是否是一个有效的 URL http://domain.com?some_param=1。定义 URL 结构的 RFC 没有明确声明这是无效结构。根据RFC 1738,第 3.3 部分

If neither <path> nor <searchpart> is present, the "/" may also be omitted.

但是,在同一文档的第 3.1 部分末尾,它说

Note that the "/" between the host (or port) and the url-path is  NOT part of the url-path.

用 curl 检查发现了一些有趣的事情

$ curl -v -I http://stackoverflow.com?test
* Rebuilt URL to: http://stackoverflow.com/?test
...

所以,问题是

这是一个有效的 URL 吗?http://domain.com?some_param=1

4

1 回答 1

0

host对于和,第 3.3 节遵循第 3.1 节port,但其余部分如该节中定义的那样。因此,如果存在或,则后面的斜线port是必需的。pathsearchpart

尽管如此,即使省略了这个斜线,工具也可能会尝试提取有效的 URL,因为各种意识形态的戒律之一是在输入上保持自由,在输出上保持保守。

于 2016-05-19T11:23:13.710 回答