29

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 slashes, as in file:///C:/a.html?

CC BY-SA 4.0
2

2 Answers 2

27

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.

CC BY-SA 3.0
1
  • 3
    Might be some regret, but it does make it easier to at a glance isolate the domain from the protocol, in my opinion
    – jjxtra
    Nov 25, 2019 at 1:33
12

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.

CC BY-SA 3.0
4
  • then why http:// contains two slashes or what does mean of first two slashes in file:// too?
    – user6117584
    Apr 5, 2016 at 17:49
  • 1
    From the following Wikipedia: File_URI_Scheme , it is explained that it is in the following format: file://<host>/<resource>, if the <host> portion is left blank, the other / following it needs to remain thus file:/// is the same as file://localhost/ . Most browser url's are in the format of <sheme>://<host>/<resource> Apr 5, 2016 at 17:51
  • @SanuelJackson why everyone is repeating same words? I'm asking what does mean of first two slashes? file:// or http://?
    – user6117584
    Apr 5, 2016 at 17:53
  • 3
    @LetDoit - those are the characters chosen as the designated separator when drafting the rfc for uri format. A uri can also contain other data such as username and password : <scheme>://<username>:<password>@<host>:<port>/<resource> is a more "complete" example. If you notice there are more than one method where : would appear before a / so I imagine that would be why they denoted // following the first : to make it easier to parse. Generally though, the concept is what the original author of the rfc decided on. Similarly, spintax uses {<word>|<word>} as that was their choice. Apr 5, 2016 at 18:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy