今天我们和同事争论这是否是一个有效的 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