Difference Between URI and URL
It's 1994 and you are creating the World Wide Web.
You need a way to find a file on any computer connected to the internet.
Not easy!
You do some research and find that there is a specification for a URI.
The URI helps you find a file on a computer.
Eureka!
What if you use the URI format but instead of finding files on a single computer you use it to find files on any computer.
And the URL was born.
Lets look at this in more detail.
We will look at URI, URL and a URN!
URI, URL and URN
URI is a standard way to locate resources and is implemented by both URL and URN.
Here is the family tree:
We have:
- URI - Uniform Resource Identifier the parent of URL and URN
With two child objects called:
- URL - Uniform Resource Locator, used to locate a resource
- URN - Gives a resource a unique name but not a location
Don't worry if you find this confusing you are not alone!
W3C the group that sets standards for the web has said there is a lot of confusion even amongst the experts:
People […] use “URL” and “URI” in ways that seem to be interchangeable
There is no wonder you are googling for the answer.
Let's take a look at each of these and give some examples of each type.
Uniform Resource Locator (URL)
URL is the term used most often and the one we use when talking about the web.
Often called a web address, the URL is what you type into the address bar of your web browser.
An example of a URL would be:
http://www.example.com/index.html?parameter=1.
A URL has a few different parts lets break these down:
- http:// - This is the protocol and lets the browser know what type of request you are making
- www.example.com - This is the hostname and points to a web server that hosts files
- index.html - This is the file that is being requested
- ?parameter=1 - This is a query variable and is a way of passing data to the server
The URL is as old as the internet. Tim Berners-Lee created them in 1994 when he invented the world wide web.
A URL is a type of URI and people often use them both when describing links.
Both are correct and this fact causes a lot of confusion for web developers and SEOs.
Here are some other examples of valid URLs:
http://example.com/index.html
- URL to webpageftp://example.com/download.zip
- A Zip file on a file servermailto:user@example.com
- A link to open an email to a userfile:///home/user/file.txt
- A file on your local devicetel:1-555-555-5555
- A link to make a call
Before we look at a URI let's look at what a URN is.
Uniform Resource Name (URN)
A URL is referring to the location of a resource.
A URN is only the name of a resource. There is no way of locating the resource using the URN on its own.
Yet, often there is a way to locate the URN using a “resolver”. So for example, if we were running a library which had books labeled with a URN like this:
urn:isbn:096139210x
Each book would have a unique number giving us the details of the book.
We could make some software that would allow us to look up details on this book using the URN.
So a URN identifies a unique resource.
Often a URN will start with the prefix urn:
but it does not have to. For example, Amazon resources start with arn:
.
Some examples of valid URNs:
urn:uuid:6e8bc430-9c3a-11d9-9669-0800200c9a66
urn:ISSN:0167-6423
urn:isbn:096139210x
arn:partition:service:region:account-id:resource
Like a URL, a URN is also a type of URI. Yet, you are unlikely to come across URNs on the web.
It helps to know that they exist, as it helps to explain why there is both a URI and a URL. As there is more than one type of URI.
Uniform Resource Identifier (URI)
A URI is a format of describing a resource on a computer.
The most common URI is by far the URL, we use them every day.
The URI sets a standard set of properties that its children must follow.
There are five properties to a URI:
- scheme - Every URI begins with a scheme such as
HTTP
orURN
- authority - The authority shows who owns the resource or its category.
example.com
is an example of authority. The authority is optional. - path - The path defines the hierarchy of a resource. In a URL this is the folder structure
forum/questions/
or the path to a URNisbn:096139210x
. - query - A query in a URL is the text after a question mark. Such as
?tag=networking&order=newest
this is a way of passing parameters to the URL. - fragment -The fragment in a URL is after a # sign like this
#top
. This tells the browser to jump to a subtitle within a webpage.
Here is an example of a URL that has all five parts of the URI:
This is a valid URL and a valid URI.
This strict five-part structure is the basis for all URIs. Both URLs and URNs use this structure to create their resource links.
Frequently Asked Questions
Should I use URL or URI when talking about the web?
When you are talking about the address in a web browser you should use the term URL.
Can you put a URN into the address bar on a browser?
There are no browsers that work with URNs.
What about relative links such as /blog/my-cool-post
, is this a URL?
Yes. Even relative URLs like this are still URLs and also URIs. It does not matter if the link is relative or absolute.
When you add a query parameter to a URI does it become a URL?
No, query parameters are part of a URL and a URI structure.
When you add a fragment to a URI does it become a URL?
No, fragments are part of a URL and a URI structure.
Is a URL and a URN the same as a URI?
Yes, URI is the parent to both a URL and a URN.
Am I wrong if I call a URL and URI?
No, a URI is a URL. A URI is an all-encompassing term to describe a URN and a URL.
Wrapping Up, Difference Between URI and URL
So what is the difference between a URI and a URL?
Well, a URL is a URI.
You can use them both to describe the same thing.
It is more common to use the term URL on the web as the URL was created for the web.
Any address that you type into the browsers address bar is a URL (and a URI).
It is more common to call them a URL.
Yet, if someone asks for you to send the URI you now know what they are asking for.
We also looked at a URN and how this is a type of URI.
It is different from a URL as it gives a unique name for a resource and not its location.
Simple!