What is the difference between a URI, a URL and a

2018-12-31 04:58发布

People talk about URLs, URIs and URNs as if they're different things, but they look the same to the naked eye.

What are the distinguishable differences between them?

30条回答
公子世无双
2楼-- · 2018-12-31 05:32

Wikipedia will give all the information you need here. Quoting from http://en.wikipedia.org/wiki/URI:

A URL is a URI that, in addition to identifying a resource, provides means of acting upon or obtaining a representation of the resource by describing its primary access mechanism or network "location".

查看更多
裙下三千臣
3楼-- · 2018-12-31 05:32

URIs came about from the need to identify resources on the Web, and other Internet resources such as electronic mailboxes in a uniform and coherent way. So, one can introduce a new type of widget: URIs to identify widget resources or use tel: URIs to have web links cause telephone calls to be made when invoked.

Some URIs provide information to locate a resource (such as a DNS host name and a path on that machine), while some are used as pure resource names. The URL is reserved for identifiers that are resource locators, including 'http' URLs such as http://stackoverflow.com, which identifies the web page at the given path on the host. Another example is 'mailto' URLs, such as mailto:fred@mail.org, which identifies the mailbox at the given address.

URNs are URIs that are used as pure resource names rather than locators. For example, the URI: mid:0E4FC272-5C02-11D9-B115-000A95B55BC8@stackoverflow.com is a URN that identifies the email message containing it in its 'Message-Id' field. The URI serves to distinguish that message from any other email message. But it does not itself provide the message's address in any store.

查看更多
倾城一夜雪
4楼-- · 2018-12-31 05:34

Due to difficulties to clearly distinguish between URI and URL, as far as I remember W3C does not make a difference any longer between URI and URL (http://www.w3.org/Addressing/).

查看更多
回忆,回不去的记忆
5楼-- · 2018-12-31 05:35

A small addition to the answers already posted, here's a Venn's diagram to sum up the theory (from Prateek Joshi's beautiful explanation):

enter image description here

And an example (also from Prateek's website):

enter image description here

查看更多
永恒的永恒
6楼-- · 2018-12-31 05:35

I was wondering about the same thing and I've found this: http://docs.kohanaphp.com/helpers/url.

You can see a clear example using the url::current() method. If you have this URL: http://example.com/kohana/index.php/welcome/home.html?query=string then using url:current() gives you the URI which, according to the documentation, is: welcome/home

查看更多
忆尘夕之涩
7楼-- · 2018-12-31 05:35

In order to answer this I'll lean on an answer I modified to another question. A good example of a URI is how you identify an Amazon S3 resource. Let's take:

s3://www-example-com/index.html [fig. 1]

which I created as a cached copy of

http://www.example.com/index.html [fig. 2]

in Amazon's S3-US-West-2 datacenter.

Even if StackOverflow would allow me to hyperlink to the s3:// protocol scheme, it wouldn't do you any good in locating the resource. Because it Identifies a Resource, fig. 1 is a valid URI. It is also a valid URN, because Amazon requires that the bucket (their term for the authority portion of the URI) be unique across datacenters. It is helpful in locating it, but it does not indicate the datacenter. Therefore it does not work as a URL.

So, how do URI, URL, and URN differ in this case?

NOTE: RFC 3986 defines URIs as scheme://authority/path?query#fragment

查看更多
登录 后发表回答