当我当前位于我网站的“根目录”时,附加查询字符串参数的正确语法是什么?
1) http://www.example.com/?foo=bar
2) http://www.example.com?foo=bar
3) http://www.example.com/&foo=bar
我确定#3是完全错误的,但我不确定1或2.我从未遇到过这种情况,它总是附加到带有扩展名的文件名 - 这个奇怪的用例出现了在我们的团队中,我一直在挠头。
答案 0 :(得分:3)
第一是唯一正确的。见RFC1738 3.3:
An HTTP URL takes the form:
http://<host>:<port>/<path>?<searchpart>
where <host> and <port> are as described in Section 3.1. If :<port>
is omitted, the port defaults to 80. No user name or password is
allowed. <path> is an HTTP selector, and <searchpart> is a query
string. The <path> is optional, as is the <searchpart> and its
preceding "?". If neither <path> nor <searchpart> is present, the "/"
may also be omitted.