Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
URL vs URI vs URN
Web DevelopmentDevOps

URL vs URI vs URN

Uniform Resource Identifiers

Andrii Chornyi

by Andrii Chornyi

Data Scientist, ML Engineer

Mar, 2024
7 min read

facebooklinkedintwitter
copy
URL vs URI vs URN

Introduction

In the digital world, terms like URL, URI, and URN are often used interchangeably, but they have distinct meanings and uses. Understanding these differences is crucial for web developers, IT professionals, and anyone working with internet technologies. This article will explore what each of these terms means, how they differ, and provide examples for a clearer understanding.

What is a URI?

A URI (Uniform Resource Identifier) is a generic term used to identify resources either on the internet or a local network. The primary purpose of a URI is to enable the identification of a resource, which can be anything from a webpage to a book or a document.

Venn Diagram

A URI typically consists of the following components:

  1. Scheme: This part indicates the protocol used to access the resource. Common schemes include http, https, ftp, mailto, and many others. The scheme is followed by a colon (:).

  2. Authority: This part is often used to specify the Internet domain of the resource, such as www.example.com. It typically includes:

    • User Information (optional): Username and password, followed by an @ symbol.
    • Host: The domain name (like example.com) or IP address.
    • Port (optional): A port number, following the host, separated by a colon. If not specified, a default port is used based on the scheme.
  3. Path: The path refers to a specific resource on the host. For instance, in a web URL, this might look like /path/to/myfile.html. It represents a hierarchical structure and is separated by slashes (/).

  4. Query (optional): A query string provides additional simple parameters, often for the purpose of database queries or refined searches. It starts with a question mark (?) and is followed by key-value pairs, usually separated by an ampersand (&). For example, ?key1=value1&key2=value2.

  5. Fragment (optional): A fragment identifier provides direction to a secondary resource, such as a section within a document. This is typically a location within a webpage. The fragment is preceded by a hash symbol (#).

In summary, the general syntax of a URI can be represented as:

URI Scheme

It's important to note that not all parts are always used in every URI. For instance, a mailto URI (like mailto:someone@example.com) does not use path, query, or fragment components. Also, URIs are a broader category that includes URLs (Uniform Resource Locators), which are URIs used specifically for locating resources on the Internet.

  • Example: https://www.example.com/page.html (a URL), urn:isbn:0451450523 (a URN).

Run Code from Your Browser - No Installation Required

Run Code from Your Browser - No Installation Required

What is a URL?

A URL (Uniform Resource Locator) is a specific type of URI that not only identifies a resource but also provides a means to locate the resource by describing its primary access mechanism and network location.

URL Scheme
  • Example: https://www.example.com/about.html - This URL locates the 'about' page on the example.com website using the HTTPS protocol.

What is a URN?

A URN (Uniform Resource Name) is another type of URI that names a resource instead of locating it. The focus of a URN is to provide a globally unique identifier for a resource, irrespective of where it is located. It is intended to remain globally unique and persistent even if the resource ceases to exist or becomes unavailable.

  • Example: urn:isbn:0451450523 - This URN uniquely identifies a book using its ISBN number, irrespective of where or how the book can be accessed.

Differences

URL vs URI

  • All URLs are URIs, but not all URIs are URLs.
  • A URI identifies a resource either by location (URL), name (URN), or both.
  • A URL is a type of URI that implies the location of the resource.

URL vs URN

  • Both URL and URN are subsets of URI.
  • A URL defines a resource's location, while a URN defines its name.
  • URLs are used when the resource is expected to be available. URNs are used for resources where persistent naming is important.

URI as a Super Set

  • URI is a superordinate concept that encompasses both URLs and URNs.
  • Think of URI as an umbrella under which both URLs (locators) and URNs (names) fall.

Start Learning Coding today and boost your Career Potential

Start Learning Coding today and boost your Career Potential

Conclusion

In summary, a URI is a more general term that refers to both URLs and URNs. A URL is a practical address used to access a resource on the internet, while a URN is a unique identifier used to identify a resource regardless of its location. Understanding these distinctions is vital for correctly implementing and referring to resources in the realm of internet technologies and web development.

FAQs

Q: Can a URI change over time?
A: Yes, a URI can change if the name or location of the resource it represents changes. However, a URN, which is a type of URI, is designed to be a persistent identifier that does not change over time.

Q: Is a URL more commonly used than a URN?
A: Yes, URLs are more commonly used in everyday internet activities, as they provide the actual path to access a resource. URNs are less common and are typically used in scenarios where a permanent, unchanging name is required.

Q: Are there any specific rules for constructing a URN?
A: Yes, URNs have specific syntax rules defined in RFC 8141. They generally include a namespace identifier and namespace-specific string, which together uniquely identify a resource.

Q: How do search engines use URLs and URIs?
A: Search engines primarily use URLs to locate and index web pages. URIs are used more broadly to identify resources, which can include web pages, images, documents, and more.

Was this article helpful?

Share:

facebooklinkedintwitter
copy

Was this article helpful?

Share:

facebooklinkedintwitter
copy

Content of this article

We're sorry to hear that something went wrong. What happened?
some-alt