URL vs URI: Key Difference Between URL and URI

Main Difference Between URL and URI

  • URL is a subset of URI that specifies where a resource exists and the mechanism for retrieving it, while URI is a superset of URL that identifies a resource.
  • The main aim of a URL is to get the location or address of a resource, whereas the main aim of a URI is to find a resource.
  • URL is used to locate only web pages; on the other hand, URI is used in HTML, XML, and other files.
  • URL contains components such as protocol, domain, path, hash, query string, etc., while URI contains components like scheme, authority, path, query, etc.
  • An example of a URL is: https://google.com while an example of a URI is: urn:isbn:0-486-27557-4.

Difference Between URL and URI
Difference Between URL and URI

Here, I have analyzed the difference between a URL and a URI and will comprehensively evaluate their pros and cons.

What is the URL?

A URL is a global address for documents and protocols to retrieve resources on a computer network. URLs occur most frequently in reference to web pages (HTTP) but can also be used for database access using JDBC, email (mailto), file transfer (FTP), and many other applications. The full form of the URL is Uniform Resource Locator.

What is URI?

A URI is a string containing characters that identify a physical or logical resource. URI follows syntax rules to ensure uniformity. Moreover, it also maintains extensibility via a hierarchical naming scheme. The full form of URI is Uniform Resource Identifier.

Types of URI
Types of URI

As mentioned in the above figure, there are two types of URIs:

  1. URL: A URL specifies a location on the computer network and a technique for retrieving it.
  2. URN: Uniform Resource Name (URN) is an internet resource that specifies the URN scheme.

Ven Diagram of URIs and URLs

Ven Diagram of URI and URL

Ven diagram of URI and URL

As mentioned in the above diagram, “your name” can be a URI because it identifies you. It cannot be a URL since it does not assist any person in finding your home location.

On the other hand, “your home location” can be a URI as well as a URL. The reason is to both identify you and give you a home location for you.

Syntax of URL

Here is the syntax of the URL:

http://www.domainname.com/folder-name/web page-file-name.htm

We can divide the above URL into the following parts:

  • Protocol: It is the first part of the URL. Here, the protocol name is Hypertext Transfer Protocol (HTTP).
  • http://www.domainname.com/:  It is your domain name. It is also known as the server ID or the host.
  • /folder-name/: It indicates that the website page referenced is “filed” in a given folder on the webserver.
  • web-page-file-name.htm: It is actually a web page file name. “.htm” is an extension for the HTML file, which shows that it is a static web page. File names can have different extensions, or it depends on how you set up a web server. There could be no extension at all, and the URL could end with a slash line (/).

Example of URL

This example URL has a folder but no extension.

https://career.guru99.com/category/heavy-industries/

This example URL has no folder.

https://www.guru99.com/what-is-sap.html

This example URL has no extension.

https://career.guru99.com/top-33-investment-banking-interview-questions-answers/

Syntax of URI

Here is a syntax of URI:

URI = scheme:[//authority]path[?query][#fragment]

The URI includes the following parts:

  • Scheme component: It is a non-empty component followed by a colon (:). The scheme contains a sequence of characters starting with a letter and followed by any combination of digits, letters, periods (.), hyphens (-), or plus (+). Examples of well-known schemes include HTTP, HTTPS, mailto, file, FTP, etc. URI schemes must be registered with the Internet Assigned Numbers Authority (IANA).
  • Authority component: It is an optional field and is preceded by //. It consists of
  1. Optional user info subcomponent that might consist of a username and password (optional).
  2. A host subcomponent containing either an IP address or a registered name.
  3. An optional port subcomponent that is followed by a colon (:)
  • Path: A path contains a sequence of segments that are separated by a slash.
  • Query component: It is optional and preceded by a question mark (?). The query component contains a query string of non-hierarchical data.
  • Fragment component: It is an optional field and is preceded by a hash (#). The fragment component includes a fragment identifier giving direction to a secondary resource.

Example of URI

No protocol is mentioned.

www.guru99.com

Domain not mentioned

what-is-sap.html

Protocol mentions

ldap://[2001:db8::7]/c=GB?objectClass?one
mailto:abc@example.com 
tel:+1-816-555-1212  
telnet://192.0.2.16:80/ 

Confusion about URN

There is a confusion about URN: if you implement protocols like https, ftp, etc., then it is called a URL, even though it is a URI.

The problem with such a debate is that appropriate RFC are extremely dense and sometimes even contradictory. For example, RFC 3986 says a URI can be either a name, a locator, or both.

Why URL?

Here are the important reasons I focus on using URL:

  • The information written in the URL gives you the ability to switch from one web page to another with just one mouse click.
  • URL tells you how to access a particular resource.
  • Whenever you type a URL into your browser or click any hypertext link, your web browser sends a request to a web server to download one or more files.
  • URL is the address of a given unique resource on the Web, including webpages, images, files, media, web applications, etc.
  • A website The URL, or domain, is one of the most crucial parts of your website. By using simple words or strings that usually end with .org, .com, or .net, you would be able to get traffic to your website.

Why URI?

Let me share the significant reasons I use URI:

  • A uniform resource identifier is essential to the semantic Web because it prevents ambiguity.
  • A URI searches for the name as well as the location of a resource or file, which is in a uniform format.
  • It has a string of characters for the specific filename and path.
  • URI provides a method for resources to be accessed by other systems over the World Wide Web or across a network. It is used by web browsers and P2P (peer-to-peer) file-sharing software to find and download files.
  • URI allows new file types to be defined without affecting the old files you have.
  • You can assign a single resource to associate with multiple representations.

Difference Between URL and URI

In our analysis, here are the main differences between a URL and a URI:

Difference Between URL and URI
URL vs URI
URL URI
URL stands for Uniform Resource Locator. URI stands for Uniform Resource Identifier.
URL is a subset of URI that specifies where a resource exists and the mechanism for retrieving it. A URI is a superset of a URL that identifies a resource either by URL, URN (Uniform Resource Name), or both.
The main aim is to get the location or address of a resource The main aim of URIs is to find a resource and differentiate it from other resources using either name or location.
URL is used to locate only web pages Used in HTML, XML, and other files, XSLT (Extensible Stylesheet Language Transformations), and more.
The scheme must be a protocol like HTTP, FTP, HTTPS, etc. In URI, the scheme may be anything like a protocol, specification, name, etc.
Protocol information is given in the URL. There is no protocol information given in the URI.
Example of URL: https://google.com Example of URI: urn:isbn:0-486-27557-4
It contains components such as protocol, domain, path, hash, query string, etc. It contains components like scheme, authority, path, query, fragment component, etc.
All URLs can be URIs Not all URIs are URLs since a URI can be a name instead of a locator.

How to Choose Between a URL and a URI

In my experience, the main difference between a URL and a URI is that a URL is a subset of a URI that specifies where a resource exists and the mechanism for retrieving it, while a URI is a superset of a URL that identifies a resource. We use URLs to locate only web pages; however, URIs are used in HTML, XML, and other files such as JSTL and XSTL.