Why HTTP:// contain two slashes and file:/// three

2020-05-20 19:50发布

I want to ask why http:// contains two slashes is it just standard to make it URL or any logically meaning? and why file:/// contains three slashes?

file:///C:/a.html

标签: url web
2条回答
ら.Afraid
2楼-- · 2020-05-20 20:00

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.

查看更多
可以哭但决不认输i
3楼-- · 2020-05-20 20:16

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.

查看更多
登录 后发表回答