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

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

    URIs identify and URLs locate; however, locators are also identifiers, so every URL is also a URI, but there are URIs which are not URLs.

    Examples

    • Roger Pate

    This is my name, which is an identifier. It is like a URI, but cannot be a URL, as it tells you nothing about my location or how to contact me. In this case it also happens to identify at least 5 other people in the USA alone.

    • 4914 West Bay Street, Nassau, Bahamas

    This is a locator, which is an identifier for that physical location. It is like both a URL and URI (since all URLs are URIs), and also identifies me indirectly as "resident of..". In this case it uniquely identifies me, but that would change if I get a roommate.

    I say "like" because these examples do not follow the required syntax.

    Popular confusion

    From Wikipedia:

    In computing, a Uniform Resource Locator (URL) is a subset of the Uniform Resource Identifier (URI) that specifies where an identified resource is available and the mechanism for retrieving it. In popular usage and in many technical documents and verbal discussions it is often incorrectly used as a synonym for URI, ... [emphasis mine]

    Because of this common confusion, many products and documentation incorrectly use one term instead of the other, assign their own distinction, or use them synonymously.

    URNs

    My name, Roger Pate, could be like a URN (Uniform Resource Name), except those are much more regulated and intended to be unique across both space and time.

    Because I currently share this name with other people, it's not globally unique and would not be appropriate as a URN. However, even if no other family used this name, I'm named after my paternal grandfather, so it still wouldn't be unique across time. And even if that wasn't the case, the possibility of naming my descendants after me make this unsuitable as a URN.

    URNs are different from URLs in this rigid uniqueness constraint, even though they both share the syntax of URIs.

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

    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".

    0 讨论(0)
  • 2020-11-22 03:00

    These are some very well-written but long-winded answers. Here is the difference as far as CodeIgniter is concerned:

    URL - http://example.com/some/page.html

    URI - /some/page.html

    Put simply, URL is the full way to indentify any resource anywhere and can have different protocols like FTP, HTTP, SCP, etc.

    URI is a resource on the current domain, so it needs less information to be found.

    In every instance that CodeIgniter uses the word URL or URI this is the difference they are talking about, though in the grand-scheme of the web, it is not 100% correct.

    0 讨论(0)
  • 2020-11-22 03:01

    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

    0 讨论(0)
  • 2020-11-22 03:04

    I found:


    A uniform resource identifier(URI) represents something of a big picture. You can split URIs/ URIs can be classified as locators (uniform resource locators- URL), or as names (uniform resource name-URN), or either both. So basically, a URN functions like a person's name and the URL depicts that person's address. So long story short, a URN defines an item's identity, while the URL provides defines the method for finding it, finally encapsulating these two concepts is the URI

    0 讨论(0)
  • 2020-11-22 03:06

    They're the same thing. A URI is a generalization of a URL. Originally, URIs were planned to be divided into URLs (addresses) and URNs (names) but then there was little difference between a URL and URI and http URIs were used as namespaces even though they didn't actually locate any resources.

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