In a URL, what is // for? [closed]

The leading // is part of the URL syntax. The inventor of the world wide web has apologized for that mistake.

Really, if you think about it, it doesn’t need the double-slash. I could have designed it not to have the double-slash. -- Sir Tim Berners-Lee, inventor of the world wide web


As for the trailing //, it's really not a double slash. The first slash separates the host name from the path. The last slash is the path. A web server can, if it wants to, treat a path of / different from an empty path, and apparently weather.com's does. As for whether this is by accident or intentional, you'd have to ask them about that.


More recently, it could be argued that the double slash does have a role. Google recommend (to avoid accidentally calling insecure content from a secure page, for example) omitting the protocol from embedded resources (stylesheets, js etc), like this

<script src="//www.google.com/js/gweb/analytics/autotrack.js"></script>

So it is now apparent that such a protocol-less URL is a fully qualified URL and not a relative URL (which would begin with a single slash).


To actually answer the question, the original specification gave the protocol http: (or possibly ftp:, gopher:, mailto:, news:, telnet:, wais:, file: or prospero:) then a // to indicate that the Uniform Resource Locator (URL) syntax was being used, then the host (optionally prefixed with user:password@) then address proper starting with another /. This was proposed in RFC 1738.

As the internet evolved, http: became the dominant protocol so browsers now assume that a prefix of http:// should be added if it isn't there.


I'd like to add to David's accepted answer:

Despite the apology of inventor of the web I think the double-slash syntax served an important purpose: to visually stand out. Double-slashes allowed easy visual distinction of URLs in a text without hyperlinks. When you saw double slashes you immediately thought it could be entered in a browser window, similar to how you thought a text containing @ could be used to send an email. It was especially crucial during the transition phase to web where protocols of that era (ftp, telnet, gopher) had their own weird notion to represent server addresses or resource paths, rarely both. Most of the problems associated with double-slashes would still exist, because double slashes are the least cryptical part of a URL, think about port numbers, percent encoding and case-sensitivity. But having a URL like http:something.com could easily be confused with my example here:something.com. Look at http:// on the other hand, how it shines like a diamond. Double-slashes have been an important part of Web symbolism and I believe it accelerated it's adoption rate too, even if it was unintentional.

They also might have made AmigaOS's job easier to differentiate between file names and URLs since AmigaOS used the file path syntax volume:path/to/destination. :)