views:

2582

answers:

9

Possible Duplicate:
What's the difference between a URI and a URL?

If you read the documentation of CodeIgniter or Kohana, there is a lot of confusion about the usage of URI and URL. Sometimes they use one and other times the other. They also incorporate URI class which makes it easier working with URLs.

I know that:

  • URI stands for Uniform Resource Identifier
  • URL stands for Uniform Resource Locator

But that doesn't make much sense. What exactly is the difference? or are they same?

+129  A: 

URIs identify and URLs locate; however, locations are also identifications, so every URL is also a URI, but there are URIs which are not URLs.

Examples

  • Roger Pate

This is my name, which is identification. It is like a URI, but cannot be a URL, 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.

I say "like" because these examples do not follow the required syntax.

Popular confusion

From Wikipedia:

In computing, a Uniform Resource Locator (URL) is a subset of the Uniform Resource Identifier (URI) that specifies where an identified resource is available and the mechanism for retrieving it. In popular usage and in many technical documents and verbal discussions it is often incorrectly used as a synonym for URI, ... [emphasis mine]

Because of this common confusion, many products and documentation incorrectly use one term instead of the other, assign their own distinction, or use them synonymously.

URNs

My name, Roger Pate, could be like a URN, except those are much more regulated and intended to be unique across both space and time.

Because I currently share this name with other people, it's not globally unique and would not be appropriate as a URN. However, even if no other family used this name, I'm named after my paternal grandfather, so it still wouldn't be unique across time. And even if that wasn't the case, the possibility of naming my descendants after me make this unsuitable as a URN.

URNs are different from URLs in this rigid uniqueness constraint, even though they both share the syntax of URIs.

Roger Pate
That is great explanation thanks :)
Sarfraz
Well said!. -----------
Rev316
Very Well Said!. ------------
this. __curious_geek
even my mother would get it now :D
migajek
thanks..this made many things clear to me :)
Krishna
+4  A: 

See this document. Specifically,

a URL is a type of URI that identifies a resource via a representation of its primary access mechanism (e.g., its network "location"), rather than by some other attributes it may have.

It's not an extremely clear term, really.

avpx
thanks that link is helpful too :)
Sarfraz
+12  A: 

In summary: a URI identifies, a URL identifies and locates.

Consider a specific edition of Shakespeare's play Romeo and Juliet, of which you have a digital copy on your home network.

You could identify the text as urn:isbn:0-486-27557-4.
That would be a URI, but more specifically a URN because it names the text.

You could also identify the text as file://hostname/sharename/RomeoAndJuliet.pdf.
That would also be a URI, but more specifically a URL because it locates the text.

(Note that my example is adapted from Wikipedia)

Greg
It's helpful to note the actual URN (to see how it compares to a URL): urn:isbn:0-486-27557-4
Michael Brewer-Davis
@Michael - It is my understanding that `ISBN 0486275574` also names the text and thus qualify as a URN. I choose a format that I believed would be more familiar to readers.
Greg
+3  A: 

Another example I like to use when thinking about URI's is the xmlns attribute of an XML document:

<rooElement xmlns:myPrefix="com.mycompany.mynode">
    <myPrefix:aNode>some text</myPrefix:aNode>
</rootElement>

In this case com.mycompany.mynode would be a URI that uniquely identifies the "myPrefix" namespace for all of the elements that use it within my XML document. Is is not a URL because it is only used to identify, not to locate something per se.

darren
+2  A: 

A URI identifies a resource either by location, or a name, or both. More often than not, most of us use URIs that defines a location to a resource. The fact that a URI can identify a resources by both name and location has lead to a lot of the confusion in my opinion. A URI has two specializations known as URL and URN.

A URL is a specialization of URI that defines the network location of a specific resource. Unlike a URN, the URL defines how the resource can be obtained. We use URLs every day in the form of http://stackoverflow.com, etc. But a URL doesn’t have to be an HTTP URL, it can be ftp://xyz.com, etc.

For more information on URI you can use the following link, http://www.eie.polyu.edu.hk/~entchsun/EIE423Lab/wiurl.html.

Swapnil
thanks for those nice links...
Sarfraz
A: 

These are some very well-written but long-winded answers.

URL - http://example.com/some/page.html

URI - /some/page.html

Put simply, URL is the full way to indentify any resource anywhere and can have different protocols like FTP, HTTP, SCP, etc.

URI is a resource on the current domain, so it needs less information to be found.

Phil Sturgeon
This answer may be over-simplified but look at the context of his question. It will be more helpful to him that waffling on about XML namespaces!
Phil Sturgeon
This answer is not only wrong but actively misleading. *Both* examples are URLs. And since every URL is also a URI, this means that *both* examples are URIs. For the purpose of demonstrating the difference between URIs and URLs, this is totally useless.
Jörg W Mittag
@Jorg: totally agreed :)
Sarfraz
This is the difference as far as CodeIgniter is concerned. In every instance they use the word URL or URI this is the difference they are talking about.Therefore in the grand-scheme of the web, it is not 100% correct but in the scope of the OP's question (the difference in CodeIgniter), this answer is perfectly correct.
Phil Sturgeon
@Phil Sturgeon - agreed, for the purpose of this question, this is how CI distinguishes between URL and URI.
Matt
@Phil Sturgeon - for the purpose of the question your answer is perfectly fine
sico87
+2  A: 

Although the terms URI and URL are strictly defined, many use the terms for other things than they are defined for.

Let’s take Apache for example. If http://example.com/foo is requested from an Apache server, you’ll have the following environment variables set:

  • REDIRECT_URL: /foo
  • REQUEST_URI: /foo

With mod_rewrite enabled, you will also have these variables:

  • REDIRECT_SCRIPT_URL: /foo
  • REDIRECT_SCRIPT_URI: http://example.com/foo
  • SCRIPT_URL: /foo
  • SCRIPT_URI: http://example.com/foo

This might be the reason for some of the confusion.

Gumbo
+3  A: 

Due to difficulties to clearly distinguish between URI and URL, as far as I remember W3C does not make a difference any longer between URI and URL (http://www.w3.org/Addressing/).

manuel aldana
that is nice info too :)
Sarfraz
+1  A: 

I was wondering about the same thing and I've found this: http://docs.kohanaphp.com/helpers/url.

You can see a clear example using the url::current() method. If you have this URL: http://localhost/kohana/index.php/welcome/home.html?query=string then using url:current() gives you the URI which, according to the documentation, is: welcome/home

dierre