Saturday, May 14, 2016

What do the // in a URI stand for?

The url spec basically has a scheme id followed by a colon, followed by a scheme specific part (RFC3986)

As you can see, the mailto scheme basically has just the email address, so something like is a complete URL.

For the http scheme, the slashes have a historical reason. In the old days (pre-1990s) many networks used double slash to indicate that the first token is a hostname.

Therefore /someplace/file.txt would mean file.txt under the /someplace directory on the current file system but //someplace/file.txt would mean /file.txt at server "someplace"

Therefore the full translation of would be:

http:Use the http protocol
//example.comConnect to
/item.htmlAsk the server for item.html

(I've omitted port and fragment for simplicity)

The // is technically unnecessary to distinguish from local server because http requires that you need to specify a host to connect to.

When the file uri was originally implemented, it had the following forms and meanings

file:./file.txtLoad file from current directory (Browser's working directory)
file:/directory/file.txtLoad file from root of current host
file://mount/file.txtAttempts to load file.txt from mount point. If mount point is invalid, attempts to load file.txt from root directory
file:///directory/file.txtLoads file.txt from root directory. This is the same as above with mount token missing.

In modern browsers, everything upto the first slash is pretty much ignored. The mountpoint still works but often the browser ignores it and treats file://mount/file.txt as file:///file.txt