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

前端 未结 30 1338
小蘑菇
小蘑菇 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条回答
  •  旧时难觅i
    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

提交回复
热议问题