A URI (Uniform Resource Identifier) and a URL (Uniform Resource Locator) are both used to identify resources on the Internet, but they do have distinct definitions.
A URI is a broader concept and has two subsets: URL and URN (Uniform Resource Name).
URI (Uniform Resource Identifier): A string of characters that identify a name or a resource on the Internet. This can be either a URL or a URN. The purpose of a URI is to provide a simple and extensible means for identifying a resource. A URI can be classified as a locator, a name, or both.
URL (Uniform Resource Locator): This is a subset of URI. A URL is a specific type of URI that identifies a resource by its location on the Internet. A URL not only identifies the resource, but also explains how to access it by specifying its location. The protocol (http, https, ftp, etc.) and domain name (or IP address) form an essential part of the URL.
URN (Uniform Resource Name): This is also a subset of URI. A URN is a unique and persistent identifier which refers to a resource without requiring its location or how to access it. They’re used for unique identification, where location is not necessary, or may not be permanent. They’re less common in everyday web use.
An easy way to understand it is: all URLs are URIs, but not all URIs are URLs. For instance, `http://www.cordero.me` is a URI and also a URL. A URN like `urn:isbn:0451450523` (which represents the ISBN for a book) is a URI, but not a URL since it doesn’t provide a method to locate or access the resource.
It’s important to note that in many practical applications and discussions, the terms URI and URL are used interchangeably. This is technically incorrect, but is very common nonetheless.
URL (Uniform Resource Locator):
These specify the location of a resource on the internet and the method to retrieve it. Here are some examples:
`http://www.cordero.me`: This is a URL that points to the main page of the website hosted at the domain `cordero.me` using the HTTP protocol.
`https://www.cordero.me/page1`: This is a URL that points to a specific page (`/page1`) on the `cordero.me` website, accessed securely using HTTPS.
`ftp://ftp.cordero.me/public/file.txt`: This is a URL for a specific file (`/public/file.txt`) on an FTP server at `ftp.cordero.me`, accessed using the FTP protocol.
URI (Uniform Resource Identifier):
These identify a resource either by location, or a name, or both. All URLs are URIs, but not all URIs are URLs. Here are some examples:
`http://www.cordero.me`: This is a URI that is also a URL. It identifies the resource by its location on the internet.
`https://www.cordero.me/page1`: This is a URI that is also a URL. It identifies a specific page on a website by its location.
`mailto:firstname.lastname@example.org`: This is a URI for an email address. It’s not a URL because it doesn’t specify the location of a resource on the Internet, but it’s a URI because it identifies a resource (an email address in this case).
`urn:isbn:978-3-16-148410-0`: This is a URI (specifically a URN, Uniform Resource Name) that identifies a book by its ISBN number. This is not a URL because it doesn’t specify the location of a resource on the internet, but it identifies a specific resource (a book in this case).
So, in short, a URL is a type of URI that describes where something is and how to access it. A URI can also be a URN, which describes a unique identifier without concern for location or access method.