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

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

    The answer is ambiguous. In Java it is frequently used in this way:

    An Uniform Resource Locator (URL) is the term used to identify an Internet resource including the scheme( http, https, ftp, news, etc.). For instance What is the difference between a URI, a URL and a URN?

    An Uniform Resource Identifier (URI) is used to identify a single document in the Web Server: For instance /questions/176264/whats-the-difference-between-a-uri-and-a-url

    In Java servlets, the URI frequently refers to the document without the web application context.

    0 讨论(0)
  • 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.

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

    See this document. Specifically,

    a URL is a type of URI that identifies a resource via a representation of its primary access mechanism (e.g., its network "location"), rather than by some other attributes it may have.

    It's not an extremely clear term, really.

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

    Although the terms URI and URL are strictly defined, many use the terms for other things than they are defined for.

    Let’s take Apache for example. If http://example.com/foo is requested from an Apache server, you’ll have the following environment variables set:

    • REDIRECT_URL: /foo
    • REQUEST_URI: /foo

    With mod_rewrite enabled, you will also have these variables:

    • REDIRECT_SCRIPT_URL: /foo
    • REDIRECT_SCRIPT_URI: http://example.com/foo
    • SCRIPT_URL: /foo
    • SCRIPT_URI: http://example.com/foo

    This might be the reason for some of the confusion.

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

    Identity = Name with Location

    Every URL(Uniform Resource Locator) is a URI(Uniform Resource Identifier), abstractly speaking, but every URI is not a URL. There is another subcategory of URI is URN (Uniform Resource Name), which is a named resource but do not specify how to locate them, like mailto, news, ISBN is URIs. Source

    URN:

    • URN Format : urn:[namespace identifier]:[namespace specific string]
    • urn: and : stand for themselves.
    • Examples:
      • urn:uuid:6e8bc430-9c3a-11d9-9669-0800200c9a66
      • urn:ISSN:0167-6423
      • urn:isbn:096139210x
      • Amazon Resource Names (ARNs) is a uniquely identify AWS resources.
        • ARN Format : arn:partition:service:region:account-id:resource

    URL:

    • URL Format : [scheme]://[Domain][Port]/[path]?[queryString]#[fragmentId]
    • :,//,? and # stand for themselves.
    • schemes are https,ftp,gopher,mailto,news,telnet,file,man,info,whatis,ldap...
    • Examples:
      • http://ip_server/path?query
      • ftp://ip_server/path
      • mailto:email-address
      • news:newsgroup-name
      • telnet://ip_server/
      • file://ip_server/path_segments
      • ldap://hostport/dn?attributes?scope?filter?extensions

    Analogy:
    To reach a person: Driving(protocol others SMS, email, phone), Address(hostname other phone-number, emailid) and person name(object name with a relative path).

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

    First of all get your mind out of confusion and take it simple and you will understand.

    URI => Uniform Resource Identifier Identifies a complete address of resource i-e location, name or both.

    URL => Uniform Resource Locator Identifies location of the resource.

    URN => Uniform Resource Name Identifies the name of the resource

    Example

    We have address https://www.google.com/folder/page.html where,

    URI(Uniform Resource Identifier) => https://www.google.com/folder/page.html

    URL(Uniform Resource Locator) => https://www.google.com/

    URN(Uniform Resource Name) => /folder/page.html

    URI => (URL + URN) or URL only or URN only

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