OK to skip slash before query string?

后端 未结 4 539
清酒与你
清酒与你 2020-12-02 11:20

Is it safe to always skip the trailing slash when appending a query string?

That is, can I use

http://example.com?querystring

inste

4条回答
  •  天命终不由人
    2020-12-02 11:34

    It is not safe to assume that. Web servers and self-contained web applications typically inspect the URL provided in the request, but there is no guarantee that they will treat /abc equal to /abc/. Web servers and self-contained web applications can do whatever they like with the information gleaned from the URL, and it will not necessarily be what you expect. You will have to find out what the convention is for the particular URL in question.

    Note, of course, that most web servers and web application frameworks try hard to accept all sorts of inputs and deal with them appropriately. Therefore, in most cases, the web server or self-contained web application will treat /abc equal to /abc/. But remember, because the server can do whatever it likes with the path, that this is simply a generic observation with potentially numerous exceptions.

提交回复
热议问题