URI vs URL: Differences and when to use them

Although in some cases a Uniform Resource Identifier (URI) and a Uniform Resource Locator (URL) can be used interchangeably, they are not the same thing.

Knowing the difference between a URI and a URL can make developing your website easier. For example, you will be able to design one more easily, since a URI or a URL will identify each resource on the web.

In short, the main difference between a URI and a URL is that the former can be a name, a location, or both, while the latter only provides the location of a resource.

In this article, we will explain in more detail the differences between a URI and a URL and their structure. In addition, we will include use cases for both a URI and a URL along with their pros and cons.

A URI or Uniform Resource Identifier is a string of characters that generally identifies any web resource by name, location, or both. A Uniform Resource Locator (URL) and a Uniform Resource Name (URN) are the two types of URIs.

Differences between URI vs URL

Consult the following comparative table to better understand the main differences between a URI and a URL.

URIsurlsURI is an acronym for Uniform Resource Identifier.URL is an acronym for Uniform Resource Locator.URI is the superset of a URN and a URL.URL is the subset of URI.The URI identifies a resource and differentiates it from others by a name, a location, or both. The URL identifies the web address or location of a unique resource. The URI contains components such as the scheme, authority, path, and query. The URL has components similar to a URI, but its authority consists of a and a port. An example of a URI is the ISBN 0-476-35557-4.An example URL would be https://.com.URI is commonly used in XML, tag library files, and other files, such as JSTL and XSTL. The URL is primarily used to search for web pages on the Internet. The URI scheme can be a protocol, a specification, or a designation such as HTTP, file, or data.The URL scheme is a protocol, such as .

URI types

After knowing the main differences between a URI and a URL, let’s focus on the two types of URIs in detail.

Uniform Resource Name (URN)

A URN is a persistent, location-independent identifier that is intended to permanently identify a resource. This means that the resource remains valid even if its data is moved to another location.

To achieve this, a URN uses the scheme to distinguish resources. For example, urn:isbn:0405999832 identifies a book by ISBN numbers.

Every Uniform Resource Name (URN) consists of at least three components:

  • URN: each URN uses the prefix urn: schema specification.
  • ID: refers to a namespace identifier that must be registered in the . It can include letters, digits, or a hyphen followed by a colon.
  • SSN: is a namespace-specific string that identifies the Internet resource. It can contain , digits, punctuation marks, and special characters.
See also  Security in web applications: What is it, how does it work and the best services

Uniform Resource Locators (URLs)

A URL specifies the method to obtain a representation of the physical location by describing the primary access mechanism or its location on the network. The resources you are trying to locate can be a web page, a video, an image, or any document posted online.

Unlike a URN, this Internet resource identifier is not always persistent and location-independent as it specifies the path to the resource, which may change over time. Also, a URL does not follow the URN scheme.

The main difference between both identifiers is that a URN only specifies the name of a resource, whereas a URL needs the access technique or protocols to retrieve the location of the resource.

In short, all URLs are URIs, but not all URIs are URLs.

URI Syntax

The syntax of a Uniform Resource Identifier (URI) defines its structure, which enables a program to understand it. This is the generic syntax of a URI:

schema:path

Now, let’s review the elements of URI syntax:

Scheme

A scheme is the first component of a URI that defines the addressing system. In some cases, URI schemes are a protocol used to access a resource. Meanwhile, other techniques may not specify any protocol.

For example, the schema about: used in web browsers, where the resource is embedded in the client and is not associated with any specific protocol.

It can contain any combination of letters, digits, plus signs, periods, or dashes followed by a colon. The most common URI schemes are HTTP, HTTPS, FTP, mailto, and file.

For example, if the URI is file:website.com/filepath/intro.pdf, the scheme name is file.

Authority

It is an optional component preceded by a double slash and terminated by a slash, question mark, or number symbol. It consists of three subcomponents:

  • userinfo: Includes a username and password separated by a colon.
  • Host: consists of one or a registered name. The IP address must be inserted in parentheses.
  • Port: a protocol used to connect to the server. It is an optional subcomponent followed by a colon.

For example, the authority component of

file:website.com/filepath/intro.pdf is website.com/.

Route

The path contains a sequence of data segments that describe the location of a resource in a directory structure. It must be empty or separated by a slash. For example, telnet://192.0.2.16:80/ or foo://info.example.com?fred is a valid URI with an empty path, since the specific location of the resource is not indicated.

See also  How to Reinstall WordPress (The Right Way)

Query

A query is an optional component that contains a query string of non-hierarchical data. It is usually a chain of pairs key=value (key=value). This component is preceded by a question mark. For example, if the URI is https://example.org/test/test1?search=test-question#part2, the query component is search=test-question.

Fragment

This optional component includes a fragment identifier that provides the address to a child resource. Refers to a different section of the parent resource. A fragment is preceded by a number symbol and terminated by the end of a URI.

For example, the component part of https://example.org/test/test1?search=test-question#part2 is part2.

A URL or Uniform Resource Locator is an identifier that only indicates the location of a web page. Refers to a web address and its access capabilities, such as HTTP, FTP, and mailto.

URL Syntax

Each URL must follow the URI syntax which has a structure similar to that of a URI. Here is an example of URL syntax:

https://www.example.com/forum/questions/?tag=networking&order=newest#top

The above URL can be broken down into the following components:

Scheme

The first part of the URL syntax is a protocol used to retrieve a resource. A URL scheme provides the type of application that the device uses to open a URL. For example, FaceTime uses a URL scheme facetime:// to make calls. Other commonly used protocols for URL schemes are:

  • Hypertext Transfer Protocol (HTTP): allows users to access data from web pages via hypertext links.
  • Hypertext Transfer Protocol Secure (HTTPS): protects data transmission between the user’s browser and the site.
  • : It is used for a file transfer between different devices over a network.

Also, some URL protocols use a mailto link to identify email addresses or a to specify database access based on user requirements.

Authority

This component is preceded by a double bar. It contains two subcomponents: a domain name and a port, the resource being accessed. The domain name is the registered name of the resource, such as .com either Google com.

Professional Tip

If you have a good idea for your domain name, don’t forget to check its availability at a .

.

As for the port, it is the specific number that identifies which web service you are requesting in a . For example, the port number for the HTTP URL is 80 and for the HTTPS URL it is 443. However, if the web server uses a standard protocol such as HTTP or HTTPS, the port is usually omitted from the URL.

See also  What is DNS and how does it work?

Route

This element identifies the specific location of a web page, post, or other file that users want to access within the domain name. A path also contains any file extensions for assets, such as images and documents.

However, not all URLs display the route component. On many modern web servers, you may not see the path component as it can be omitted to shorten URLs. Some examples of paths are …/software/htp/index.html or …/forum/question/.

Querystring

This string provides data about the resource on the web server and is preceded by a question mark. It usually contains a pair of keys and values ​​separated by an ampersand. For example, ?tag=networking&order=newest.

The query string stores data, since the HTTP protocol is stateless. This means that each request is independent and not related to the previous request. As a result, the connection between a browser and a web server will be automatically closed once the client request completes.

Also, the string is known as URL query parameters which can be used for some purpose, such as search results of a web page. It will help users navigate the content of a resource. For example, users can easily find product information on a .

Fragment identifiers

A snippet or anchor identifier usually appears at the end of a URL and is introduced by a pound sign. It is an optional component to direct a web browser to a child resource. It refers to a specific section within a web page.

In an HTML page, the browser will jump to the specific section tagged by a snippet.

For example, if the URL is https://example.com/results.html#intro, it will go directly to the intro tagged on the page named results.html.

Reasons to use a Uniform Resource Identifier (URI)

Using a URI helps create standard rules for the use of a resource, including access, update, search, or download. Provides an easy way to identify Internet resources.

Here are three use cases for a URI:

  • Audiovisual works: ISAN is a serial code number used to identify audiovisual works and versions, such as movies, TV shows or documentaries. Using the scheme urn:, URI can identify the ISAN without the need for a protocol or a way to access it. For example, urn:isan:0000-0000-2CEA-0000-1-0000-0000-Y, which refers to the…
Loading Facebook Comments ...
Loading Disqus Comments ...