Do file URLs start with 3 slashes


HTTP starts with two slashes. E.g.

Same goes for FTP. E.g.

However, file "URLs" start with three slashes. E.g. Reading a pdf file using chrome, the URL would be file:///D:/Desktop/Book.pdf.

Why do file URLs use three slashes?

Best Answer

As others have mentioned, the file schema is in the form "file://<host>/<path>". Though most browsers won't have a problem with only two slashes, and rightfully so.

All things being equal, the triple slash and "localhost" keyword only exist to ensure conformance with valid URI/URL syntax. In the context of the file schema, the host is meaningless since it loads directly from a filesystem without any explicit transfer protocol or server document path. Because it's not HTTP, it can't load from a standard web server where in theory you could have multiple local virtual hosts set up. And it can't load from a standard network volume that's technically another "host", since the browser just uses the volume name like "file:///volumes/foo". Finally, trying things like "file://" doesn't work. There's probably some reason for supporting an external host, but I can't think of any.

The IETF is currently drafting changes to remove the triple-slash requirement, though the draft also adds a few oddball possibilities like file:c|/path and even file://///

"3. This specification neither defines nor forbids a mechanism for accessing non-local files."