Why does http:// contain two slashes and file:/// three in a browser navigation bar?

后端 未结 2 1568
北恋
北恋 2021-02-01 23:10

Why does http:// contain two slashes—is that just a standard for a URL, or does it have any logical meaning? And why does file:/// contain three slashe

相关标签:
2条回答
  • 2021-02-01 23:26

    As mentioned in this superuser post:

    The complete syntax is file://host/path.

    If the host is localhost, it can be omitted, resulting in file:///path.

    In other words, referring to files in your computer is just like referring to files in localhost.

    0 讨论(0)
  • 2021-02-01 23:38

    The authority component of a URI has to be preceded by //:

    The authority component is preceded by a double slash ("//") […]

    This is also why not all URIs contain the double slash: because not all URIs have an authority component (e.g., URIs using the mailto scheme, the xmpp scheme, etc.).


    If you wonder why the double slash instead of something else (or nothing) was chosen for (HTTP) URIs, see Tim Berners-Lee’s FAQ Why the //, #, etc? → What is the history of the //?

    tl;dr: He copied the filename syntax which Apollo used.

    By the way, he regrets that choice:

    I have to say that now I regret that the syntax is so clumsy. I would like http://www.example.com/foo/bar/baz to be just written http:com/example/foo/bar/baz where the client would figure out that www.example.com existed and was the server to contact. But it is too late now.

    0 讨论(0)
提交回复
热议问题