What's the Difference Between URL and URI?

Good question, and something I’ve often wondered. You hear people using both terms the whole time so let’s lay this one to rest.

So I’m sitting in this café writing some code and probably looking like a bit of a geek. Fair enough, that happens. For various reasons I want to have a variable in my webapp’s registry that stores the URL of the current page. Or is it URI? I’m at a bit of a loss on what to call it.

What is a URL?

URL stands for Uniform Resource Locator which means it’s a reference to a specific location. Importantly the location must be on the web, although this isn’t indicated within it’s name. More

What is a URI?

In relation to a URL a URI is like a superclass. It stands for Uniform Resource Identifier which means it’s a reference to a specific thing. This thing could be just about anything addressable. For example a location on the web!

What’s the difference really? Why don’t we just use URL?

We should do if we are talking about web addresses! The distinction is that a URL provides information on how to get to the resource (Eg. http, https, ftp, mailto, etc). A URI can be relative (Eg. /path/to/file.jpg) or missing the protocol (Eg. //www.norestfortheweekend.com/2009/). These are both valid URIs but not URLs.

Hidden Extras

A URL is a URI but a URI is not necessarily a URL. We see this kind of relationship in programming with classes. Another ‘subclass’ of URI which not as many people have heard of is the URN.

URNs (Uniform Resource Name) start with urn: followed by a string identifying something. They are used for identification purposes rather than as a way of finding (locating) things as URLs are. Something that has some kind of universal identifier can be formatted as a URN. A good example of this is books. The majority of books at retail have an ISBN. The ISBN is their universal identifier; it doesn’t point to where you can find the book, or contain any of the books subject matter. It just identifies it in a way that there is no confusion as to what you’re talking about.

An ISBN can be expressed as a URN: urn:isbn:1582408181.

Footnotes

For more wordy explanations, check out the wikipedia articles on URIs, URLs and URNs!

Comments