【问题标题】:HTTP GET "www.foo.com/content" and "www.foo.com/content/" are different?HTTP GET "www.foo.com/content" 和 "www.foo.com/content/" 有什么不同?
【发布时间】:2016-04-18 23:24:40
【问题描述】:

我正在使用 Firefox。

我在这个网页上阅读: https://gitbookio.gitbooks.io/javascript/content/

我不小心输入了,最后只省略了“/”:https://gitbookio.gitbooks.io/javascript/content ...它显示的内容没有格式。

我听说 HTTP GET 请求 ...centent/...centent 有什么不同。我所知道的是,请求...centent/ 将返回该目录的内容列表或显示该目录的默认值,请求...content 将返回该文件的内容(content)。我对吗?以及为什么以及如何上述两个链接返回不同? (这种情况看起来像是网站的错误)

【问题讨论】:

    标签: http web get


    【解决方案1】:

    在服务器端,没有规则服务器应该输出带有或不带有斜杠的内容。 HTTP 没有目录的概念。一切都只是一种资源。

    但路径在浏览器端的解释方式有所不同。

    在这种情况下,如果没有尾部斜杠,浏览器会认为它正在请求 /javascript 中名为“content”的资源。

    当它查找告诉浏览器如何设置内容样式的 CSS 样式表时,它会在 /javascript 中查找该文件,因为该页面使用了相对链接:

    <link rel="stylesheet" href="gitbook/style.css">
    <link rel="stylesheet" href="gitbook/plugins/gitbook-plugin-exercises/exercises.css">
    

    对于浏览器,当不使用斜杠时,第一个 URL 会转换为

    https://gitbookio.gitbooks.io/javascript/gitbook/style.css
    

    带有斜杠,它转换为

    https://gitbookio.gitbooks.io/javascript/content/gitbook/style.css
    

    这是不好的做法,或者是一种错误,取决于您的观点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-20
      • 2015-08-22
      • 2021-10-25
      • 1970-01-01
      • 1970-01-01
      • 2017-11-28
      • 1970-01-01
      相关资源
      最近更新 更多