Being an internet user, you may have encountered the acronyms ‘URL’ and ‘URI’ multiple times. These are two of the most important concepts of the web and are usually used interchangeably. But they aren’t the same.
One significant difference between URL and URI is that URI can represent a resource’s URN as well as URL simultaneously, whereas URL can only specify a resource’s address on the internet.
In this article, we will explain URL and URI individually and the differences between them.
What is URI?
A URI (Uniform Resource Identifier) is a string of characters used to identify a resource on the internet using name, location, or both.
A URI has two subsets: URN (Uniform Resource Number) and URL (Uniform Resource Locator). If it contains only one name, it means it is not a URL. Instead of seeing URI directly, we usually see the URN and URL in the real world.
URI also contains a scheme, authority, path, query, and fragment. We’ve briefly explained all these components below.
Syntax of URI
scheme:[//authority]path[?query][#fragment]
Scheme: URI’s first component is a scheme which contains a sequence of characters (this can be any combination of digits, letters, hyphens or plus signs) followed by a colon (:). The popular schemes are HTTP, file, data, FTP, and IRC. The schemes need to be registered with IANA.
Authority: It is optional and preceded by (//) two slashes. It contains 3 sub-components:
- Userinfo: It contains a username and an optional password which are separated by a colon. Userinfo is followed by the @ symbol.
- Host: It contains either an IP address or a registered name. The IP address must be enclosed within brackets [].
- Port: Optional
Path: It consists of a sequence of path segments that are separated with a slash (/). The URI always specifies the path, which may be of 0 length or empty.
Query: It is an optional component that is preceded by a question mark (?) and contains a query string of non-hierarchical data.
Fragment: It is an optional component which is preceded by a hash symbol and consists of a fragment identifier which gives direction to a secondary resource.
Examples of URI
- foo://example.com:8042/over/there?name=ferret#nose
- mailto:[email protected]
- news:comp.infosystems.www.servers.unix
What is the importance of using URI?
Here are the reasons for using URI:
- It is important to the semantic web as it prevents ambiguity
- It is a string of characters for the specific path and filename
- URI provides a way for resources to be accessed by other systems across a network or over the World Wide Web. It is used by P2P (Peer to Peer) file-sharing software and web browsers to find and download the files
- You can assign one resource to associate with various representations
What is a URL?
A URL (Uniform Resource Locator), commonly known as a website’s address is used for finding the location of a resource on the web. It is a reference for a resource and a way to access the same.
A URL shows a unique resource which can be a CSS document, an image, an HTML page, etc.
Syntax of URL
Every HTTP URL follows the syntax of its generic URI. Hence, the URL’s syntax is similar to the syntax of the URI, which is given below:
scheme:[//authority]path[?query][#fragment]
The URL consists of the following components:
Scheme: The first component of the URL is a scheme, which represents a protocol that a browser needs to use to request the resource. The commonly used protocols for websites are HTTPS or HTTP.
Authority: It includes two sub-components, Port and Domain Name, which are separated by a colon. The domain name can be anything, the resource’s registered name like bigrock.in and the port is the technical gate for accessing the resource on a web server. The port number 443 is used for HTTPS and 80 is used for HTTP.
Path: It indicates the entire path to a resource on the web server. It can be something like software/htp/index.html.
Query String: It is the string containing the value pair and name. If it is used in a URL, it follows the path and gives information like “?key1=value1&key2=value2”.
Fragment: It is an optional component, preceded by a hash symbol. It consists of a fragment identifier that provides the direction to a secondary resource.
Examples of URLs
What is the importance of using a URL?
Here are the reasons for using URLs:
- The information included in the URL allows you to switch from one web page to the other
- URL tells you how to access a resource
- Whenever you enter a URL into your browser or click through a hypertext link, your browser sends a request to a server for downloading one or more files
- A domain or website URL is a crucial part of your website. By using a string or simple words that usually end with popular TLDs like .com, .net, or .org, you’ll be able to attract traffic to your website.
Differences between URL and URI
URL |
URI |
The main aim is to get a resource’s location or address | The main aim is to find a resource and differentiate it from other resources using either location or name |
It is used only to locate the web pages | It is used in XML, HTML, and other files like XSLT (Extensible Stylesheet Language Transformations) and more |
Protocol information is given | Protocol information is not given |
All URLs can be URIs | Not all the URIs are URLs as a URI can be a name instead of a locator |
It has components like protocol, domain, path, hash, query string, etc. | It has components like scheme, authority, path, query, fragment component, etc. |
The scheme should be a protocol like FTP, HTTP, HTTPS, etc. | The scheme can be anything like name, specification, etc. |
Identifying and locating resources on the web
With several resources available on the web, it is essential to understand the right way to identify and locate individual resources. While URIs are used for identifying resources with either a location, name or both, URLs are a subset of URIs that identify the location of resources on the web.