Skip to main content

URL or URI ohh!! its too confusing

Since the days of my second semester in my engineering when I came to know about URI and URL, I always had this confusion in my mind which took ages to get cleared.

Here is a small post which gives briefs about URI, URI and URN, and what are the differences between them.

Lets check what Wikipedia has to say on all of this.

  • Wikipedia on Uniform resource locator(URL)

A uniform resource locator (URL) is a specific character string that constitutes a reference to an Internet resource.
A URL is technically a type of uniform resource identifier (URI) but in many technical documents and verbal discussions URL is often used as a synonym for URI

  • Wikipedia on Uniform resource identifier(URI)

 A uniform resource identifier (URI) is a string of characters used to identify a name or a resource. Such identification enables interaction with representations of the resource over a network (typically the World Wide Web) using specific protocols.

  • Wikipedia on Uniform resource name(URN)

Uniform resource names (URNs) are intended to serve as persistent, location-independent resource identifiers and are designed to.............

And now comes the part where we quote some relations and differences among these 

  • Wikipedia on their relation/difference

URIs can be classified as locators (URLs), as names (URNs), or as both. A uniform resource name (URN) functions like a person's name, while a uniform resource locator (URL) resembles that person's street address. In other words: the URN defines an item's identity, while the URL provides a method for finding it.
A URL is a URI that, "in addition to identifying a resource, provides a means of locating the resource by describing its primary access mechanism (e.g., its network location)"

  • And W3C on the relation/difference [RFC3986]

A URI can be further classified as a locator, a name, or both.  The term "Uniform Resource Locator" (URL) refers to the subset of URIs that, in addition to identifying a resource, provide a means of locating the resource by describing its primary access mechanism (e.g., its network "location").  The term "Uniform Resource Name" (URN) has been used historically to refer to both URIs under the "urn" scheme [RFC2141], which are required to remain globally unique and persistent even when the resource ceases to exist or becomes unavailable, and to any other URI with the properties of a name

So we can deduce this out of all the above information.


URIs identify an name or a resource and URLs locate a resource(and of-course also identify) and URNs identify a name. As locations are also identifications, so every URL is also a URI. 
Thus URI is a superset of URL and URN.

Here is an example quoted from a related posting on Stackoverflow to make things little clearer
  • Roger Pate 
This is my name, which is identification. It is like a URI, but cannot be a URL (its probably a URN), as it tells you nothing about my location or how to contact me. In this case it also happens to identify at least 5 other people in the USA alone. 
  • 4914 West Bay Street, Nassau, Bahamas 
This is a location, which is identification for that physical location. It is like both a URL and URI (since all URLs are URIs), and also identifies me indirectly as "resident of..". In this case it uniquely identifies me, but that would change if I get a roommate.

Here is the crux of the discussion

  • URL - is a type of URI which 

    • follow this syntax  "scheme://domain:port/path?query_string#fragment_id" 
      • where the scheme name defines the namespace, purpose, and the syntax of the remaining part of the URL
    • have Global scope[RFC1736](are unique in entire world). 
    • So a few examples can be
      • http://example.org:80/index.html(or simply http://example.org:80/)
      • http://example.org/absolute/URI/with/absolute/path/to/resource.txt
      • ftp://asmith@ftp.example.org
      • mailto:bob@example.com
      • ../css/style.css is a URL only if the browser(or resource) has an (absolute) URL for its referer document, something like http://example.org:80/index.html.  So that the resource understands the absolute locater and then looks for the current resource relative to it.

  • URN  - is a type of URI which

    • follows this syntax "<URN> ::= "urn:" <NID> ":" <NSS>" [RFC2141]
      • where <NID> is the Namespace Identifier, and <NSS> is the Namespace Specific String.  The leading "urn:" sequence is case-insensitive.
    • So a few examples can be
      • urn:isbn:0451450523 (The URN for The Last Unicorn 1968 book, identified by its book number.)
      • urn:isan:0000-0000-9E59-0000-O-0000-0000-2 (The URN for Spider-Man (2002 film) identified by its audiovisual number.)
      • urn:issn:0167-6423 (The URN for the Science of Computer Programming (scientific journal), identified by its serial number.)
      • urn:ietf:rfc:2648 (The URN for the IETF's RFC 2648.)
      • urn:mpeg:mpeg7:schema:2001 (Default Namespace Rules for MPEG-7 video metadata.)
      • urn:www.agxml.org:schemas:all:2:0 (A non-standard URN representing a namespace for Schema "Agricultural Markup Language 2.0 for Grain and Oilseed Business".)
      • urn:sha1:YNCKHTQCWBTRNJIV4WNAE52SJUQCZO5C (A non-standard URN representing a specific MP3 file of the I have a dream speech by Martin Luther King by its SHA-1 hash Base32 encoded.)

  • URI - is a URL, a URN or both [RFC3986]  Or, all URLs and URNs are URIs

    • So a few examples
      • ftp://ftp.is.co.za/rfc/rfc1808.txt (an FTP scheme/protocol URL)
      • http://www.ietf.org/rfc/rfc2396.txt (a simple HTTP scheme/protocol URL )
      • ldap://[2001:db8::7]/c=GB?objectClass?one (LDAP scheme/protocol URL)
      • mailto:John.Doe@example.com (email scheme/protocol URL )
      • news:comp.infosystems.www.servers.unix (also a URL)
      • tel:+1-816-555-1212 (also a URL)
      • telnet://192.0.2.16:80/  (also a URL)
      • urn:oasis:names:specification:docbook:dtd:xml:4.1.2 (also a URN) 
Before we close, there is an important piece of information I'd like to share. [RFC3305]

"Due to difficulties to clearly distinguish between URI and URL or may be other reasons as well, W3C seems to lessen the importance of this additional level of hierarchy (i.e. URLs and URNs)."

So who knows, may be after sometime they will officially keep only URI and discard any other UR* terms

Hope this helps in clearing the confusions.

So long,
Sandeep Rajoria

Comments

Popular posts from this blog

Multi Tenancy with Codeigniter

In this post I will show you how I converted my normal Codeigniter application into a multi-tenant system.(first step to a SaaS implementation) Note - This implementation is a separate DB multi-tenancy implementation. Lets say we have an up and running CI application name ci_app , with the directory structure like this ./application ./application/config ./application/...so many other important directories ./asset ./asset/js ./asset/images ./asset/css ./system ./index.php which is accessed through browser like http://localhost/ci_app So to implement the multi-tenant arch we are most concerned about the following files, and we will be editing them ./index.php ./application/config/config.php ./application/config/database.php And also we need to create a few new ones Create a tenant folder in your www root directory, lets say tenant_1 Cut the ./index.php from ci_app and paste it in tenant_1 directory  Create a blank file config.php in tenant_1 directory Crea

Profiling and checking PHP error_reporting in a Codeigniter App, without editing the config!!

Hi all, You must have definitely used the Profiling in Codeigniter and error_reporting many a times in Development and Testing environment, but I am sure you must have missed it on a real Production environment. As there are scenarios, where you want to quickly debug the Production application and find out what PHP errors is the application throwing, check the page profile, that too without putting the time and effort in replicating the whole production environment on your local machine, or perhaps a testing server. This small piece of code(we could perhaps call it a hack), which I have used in almost all of my CI applications, will make your life very easy, without losing anything on the security of the system. Following points, essentially sum up what exactly it does - Check for the dev(or root or admin, whichever name you use for the su access), if it is logged in, as we don't want others to see all the Profile data and other errors. Check for a specific query str

D3.js, the most powerful visualization library I came across

Hello Friends!! This post is dedicated to D3.js , which I came across a few months back. Prior to that, I always preferred Google Charts which catered to most of my charting needs. However, since I switched to D3.js I could not find a good reason to move back to Google Chart. If we take a very crude analogy, D3.js would be analogous to an Ubuntu of the OS world, while Google Charts could easily be a Windows 7(just that both of them are free in this case); in the sense that the control and the power the user(in our case the developer) gets from D3.js while working with it, is unmatchable . While Google Charts is simply too cool and simple for a free charting tool, but D3.js is a library which lets you create any chart that you could think and conceptualize, with so much of ease, and it lets you link any kind of interaction/control that you would want to put on events, on any of the elements of the chart. D3.js, like RaphaelJS and PaperJS is a library which is developed to