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

前端 未结 30 1272
小蘑菇
小蘑菇 2020-11-22 02:18

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

W

相关标签:
30条回答
  • 2020-11-22 02:39

    URI => http://en.wikipedia.org/wiki/Uniform_Resource_Identifier

    URL's are a subset of URI's (which also contain URNs).

    Basically, a URI is a general identifier, where a URL specifies a location and a URN specifies a name.

    0 讨论(0)
  • 2020-11-22 02:40

    URI is kind of the super class of URL's and URN's. Wikipedia has a fine article about them with links to the right set of RFCs.

    0 讨论(0)
  • 2020-11-22 02:40

    The best (technical) summary imo is this one

    IRI, URI, URL, URN and their differences from Jan Martin Keil:

    IRI, URI, URL, URN and their differences

    Everybody dealing with the Semantic Web repeatedly comes across the terms IRI, URI, URL and URN. Nevertheless, I frequently observe that there is some confusion about their exact meaning. And, of course, others noticed that as well (see e.g. RFC3305 or search on Google). To be honest, I even was confused myself at the outset. But actually the issue is not that complex. Let’s have a look on the definitions of the mentioned terms to see what the differences are:

    URI

    A Uniform Resource Identifier is a compact sequence of characters that identifies an abstract or physical resource. The set of characters is limited to US-ASCII excluding some reserved characters. Characters outside the set of allowed characters can be represented using Percent-Encoding. A URI can be used as a locator, a name, or both. If a URI is a locator, it describes a resource’s primary access mechanism. If a URI is a name, it identifies a resource by giving it a unique name. The exact specifications of syntax and semantics of a URI depend on the used Scheme that is defined by the characters before the first colon. [RFC3986]

    URN

    A Uniform Resource Name is a URI in the scheme urn intended to serve as persistent, location-independent, resource identifier. Historically, the term also referred to any URI. [RFC3986] A URN consists of a Namespace Identifier (NID) and a Namespace Specific String (NSS): urn:: The syntax and semantics of the NSS is specific specific for each NID. Beside the registered NIDs, there exist several more NIDs, that did not go through the official registration process. [RFC2141]

    URL

    A Uniform Resource Locator is a URI that, in addition to identifying a resource, provides a means of locating the resource by describing its primary access mechanism [RFC3986]. As there is no exact definition of URL by means of a set of Schemes, "URL is a useful but informal concept", usually referring to a subset of URIs that do not contain URNs [RFC3305].

    IRI

    An Internationalized Resource Identifier is defined similarly to a URI, but the character set is extended to the Universal Coded Character Set. Therefore, it can contain any Latin and non Latin characters except the reserved characters. Instead of extending the definition of URI, the term IRI was introduced to allow for a clear distinction and avoid incompatibilities. IRIs are meant to replace URIs in identifying resources in situations where the Universal Coded Character Set is supported. By definition, every URI is an IRI. Furthermore, there is a defined surjective mapping of IRIs to URIs: Every IRI can be mapped to exactly one URI, but different IRIs might map to the same URI. Therefore, the conversion back from a URI to an IRI may not produce the original IRI. [RFC3987]

    Summarizing we can say:

    IRI is a superset of URI (IRI ⊃ URI)
    URI is a superset of URL (URI ⊃ URL)
    URI is a superset of URN (URI ⊃ URN)
    URL and URN are disjoint (URL ∩ URN = ∅)
    

    Conclusions for Semantic Web Issues

    RDF explicitly allows to use IRIs to name entities [RFC3987]. This means that we can use almost every character in entity names. On the other hand, we often have to deal with early state software. Thus, it is not unlikely to run into problems using non ASCII characters. Therefore, I suggest to avoid non URI names for entities and recommend to use http URIs [LINKED-DATA]. To put it briefly: only use URLs to name your entities. Of course, we can refer to existing entities named by a URN. However, we should avoid to newly create this kind of identifiers.

    0 讨论(0)
  • 2020-11-22 02:41

    Easy to explain:

    Lets assume the following

    URI is your Name

    URL is your address with your name in-order to communicate with you.

    • my name is Loyola

      Loyola is URI

    • my address is TN, Chennai 600001.

    TN, Chennai 600 001, Loyola is URL

    Hope you understand,

    Now lets see a precise example

    http://www.google.com/fistpage.html

    in the above you can communicate with a page called firstpage.html (URI) using following http://www.google.com/fistpage.html(URL).

    Hence URI is subset of URL but not vice-versa.

    0 讨论(0)
  • 2020-11-22 02:42

    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?

    • fig. 1 is a URI
    • fig. 1 is a URN
    • fig. 2 is a URI
    • fig. 2 is a URL
    • The URL for fig. 1 is http://www-example-com.s3-website-us-west-2.amazonaws.com/
      • also http://www-example-com.s3.amazonaws.com/index.html
      • but not http://www-example-com.s3.amazonaws.com/ (no datacenter and no filename is too generic for Amazon S3)

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

    0 讨论(0)
  • 2020-11-22 02:43

    This is one of the most confusing and possibly irrelevant topics I've encountered as a web professional.

    As I understand it, a URI is a description of something, following an accepted format, that can define both or either the unique name (identification) of something and its location.

    There are two basic subsets - URLs, which define location (especially to a browser trying to look up a webpage) and URNs, which define the unique name of something.

    I tend to think of URNs as being similar to GUIDs. They are simply a standardized methodology for providing unique names for things. As in the namespace declarative that uses a company's name - it's not like there is a resource sitting on a server somewhere to correspond to that line of text - it simply uniquely identifies something.

    I also tend to completely avoid the term URI and discuss things only in terms of URL or URN as appropriate, because it causes so much confusion. The question we should really try answering for people isn't so much the semantics, but how to identify when encountering the terms whether or not there is any practical difference in them that will change the approach to a programming situation. For example, if someone corrects me in conversation and says, "oh, that's not a URL it's a URI" I know they're full of it. If someone says "we're using a URN to define the resource" I'm more likely to understand we are only naming it uniquely, not locating it on a server.

    If I'm way off base - please let me know!

    0 讨论(0)
提交回复
热议问题