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

前端 未结 30 1302
小蘑菇
小蘑菇 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:47

    From RFC 3986:

    A URI can be further classified as a locator, a name, or both. The term "Uniform Resource Locator" (URL) refers to the subset of URIs that, in addition to identifying a resource, provide a means of locating the resource by describing its primary access mechanism (e.g., its network "location"). The term "Uniform Resource Name" (URN) has been used historically to refer to both URIs under the "urn" scheme [RFC2141], which are required to remain globally unique and persistent even when the resource ceases to exist or becomes unavailable, and to any other URI with the properties of a name.

    So all URLs are URIs (actually not quite - see below), and all URNs are URIs - but URNs and URLs are different, so you can't say that all URIs are URLs.

    EDIT: I had previously thought that all URLs are valid URIs, but as per comments:

    Not "all URLs are URIs". It depends on the interpretation of the RFC. For example in Java the URI parser does not like [ or ] and that's because the spec says "should not" and not "shall not".

    So that muddies the waters further, unfortunately.

    If you haven't already read Roger Pate's answer, I'd advise doing so as well.

提交回复
热议问题