URL,URN,URI

来源:互联网 发布:电脑下载itunes软件 编辑:程序博客网 时间:2024/05/06 22:23

URLs vs. URIs: Differences and Examples


There are many classic tech debates, and the question of what to formally call web addresses is one of the most nuanced. The way this normally manifests is someone asks for the "URL" to put into his or her browser, and someone perks up with,

Actually, that's called a URI, not a URL...

The response to this correction can range from quietly thinking this person needs to get out more, to agreeing indifferently via shoulder shrug, to removing the safety clasp on a Katana. This page hopes to serve as a simple, one page summary for navigating the subtleties of this debate.

URI, URL, URN

As the image above indicates, there are three distinct components at play here. It's usually best to go to the source when discussing matters like these, so here's an exerpt from Tim Berners-Lee, et. al. inRFC 3986: Uniform Resource Identifier (URI): Generic Syntax


A Uniform Resource Identifier (URI) is a compact sequence of characters that identifies an abstract or physical resource.


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


Wikipedia captures this well with the following simplification:


One can classify URIs as locators (URLs), or as names (URNs), or as both. A Uniform Resource Name (URN) functions like a person's name, while a Uniform Resource Locator (URL) resembles that person's street address. In other words: the URN defines an item's identity, while the URL provides a method for finding it.


So we get a few things from these descriptions:

  1. First of all (as we see in the diagram as well) a URL isa type of URI. So if someone tells you that a URL is not a URI, he's wrong. But that doesn't mean all URIs are URLs. All butterflies fly, but not everything that flies is a butterfly.
  2. The part that makes a URI a URL is the inclusion of the "access mechanism", or "network location", e.g.http:// orftp://.
  3. The URN is the "globally unique" part of the identification; it's a unique name.

So let's look at some examples of URIs--again from the RFC:

  • ftp://ftp.is.co.za/rfc/rfc1808.txt
  • http://www.ietf.org/rfc/rfc2396.txt
  • ldap://[2001:db8::7]/c=GB?objectClass?one
  • mailto:John.Doe@example.com
  • news:comp.infosystems.www.servers.unix
  • tel:+1-816-555-1212
  • telnet://192.0.2.16:80/
  • urn:oasis:names:specification:docbook:dtd:xml:4.1.2

Those are all URIs, and some of them are URLs. Which are URLs? The ones that show you how to get to them. Again, the name vs. address analogy serves well.

Summary

So this brings us to the all-important question:Which is the more proper term when referring to web addresses? Based on the dozen or so articles and RFCs I read while researching for this post, I'd say thatURI is probably the better term to use.



Why?

Well, because we often use URIs in forms that don't technically qualify as a URL. For example, you might be told that a file you need is located atfiles.hp.com. That's a URI, not a URL--and that system might very well respond to many protocols over many ports. If you go tohttp://files.hp.com you could conceivably get completely different content than if you go toftp://files.hp.com. And this type of thing is only getting more common. Think of all the different services that live on the various Google domains.

So, if you use URI you'll always be technically correct, and if you useURL you might not be. Finally, there is significant chatter around the term "URL" being--or becoming--deprecated. So URI is a fairly safe choice in terms of accuracy.

That being said, Dafydd Stuttard has a different view, which is that the terms are near enough the same so as to make it pure pedantry to differentiate. InThe Web Application Hacker's Handbook he states:


The correct technical term for a URL is actually URI (or uniform resource identifier), but this term is really only used in formal specifications and by those who wish to exhibit their pedantry.


Indeed.

Final word? If you don't mind being "that guy", URI is probably the more accurate term to use. But if you are in the linguist / "use what's understood" camp, feel free to side with Dafydd and go withURL. ::






原创粉丝点击