28
  1. Absolute
    http://www.example.com/images/icons.png

  2. Relative
    ../images/icons.png

  3. ???
    /images/icons.png

  4. ???
    //www.example.com/images/icons.png

Do URL types 3 and 4 have names? One place I've seen type 4 being used is on Slashdot.

Michael
  • 8,362
  • 6
  • 61
  • 88
cherouvim
  • 31,725
  • 15
  • 104
  • 153
  • 3
    @Esko: Browsers seem to understand type 4. I think they are useful for when you serve both from http and https and you want to have the same html source files but with absolute references. – cherouvim Apr 13 '09 at 07:21
  • 4
    @Esko except for the fact that it is **not** malformed... – sjstrutt Apr 13 '09 at 08:05
  • 1
    @Colargol If you see my response, that is also document-relative. – sjstrutt Apr 13 '09 at 19:58

5 Answers5

52
  1. Absolute http://www.example.com/images/icons.png
  2. Document-Relative ../images/icons.png
  3. Root-Relative /images/icons.png
  4. Protocol-Relative //www.example.com/images/icons.png

For #4, I've also often called them "Protocol-Agnostic"

sjstrutt
  • 5,625
  • 6
  • 25
  • 21
  • 4
    @Alnitak All terminology is made up. What's important is everyone uses the same terminology so we can communicate. – Ian Newson Mar 15 '13 at 11:16
  • 1
    @IanNewson I think you just made my point for me. The terminology used here is _not_ the same as everyone else uses. – Alnitak Mar 15 '13 at 12:52
  • @Alnitak I agree with you, I upvoted your answer. My criticism is that your comment doesn't criticise this answer for the right reasons. – Ian Newson Mar 15 '13 at 13:32
45

Type 1 is just a "URI" (sometimes called an "absolute URI").

For types 2, 3 and 4 the definitive answers are in RFC 3986, section 4.2.

They are all "relative references", but according to the RFC are qualified thus:

  • ../images/icons.png - "relative path reference"
  • /images/icons.png - "absolute path reference"
  • //.../icons.png - "network path reference"

The latter is often used if you want to specify a URL containing a domain name, but where you want the protocol to match the protocol used to access the current resource. For example, if your images are downloaded from a CDN, you could use this to default to https if the current page was also downloaded via https, thus preventing the warning about including non-secure resources in a secure page.

Community
  • 1
  • 1
Alnitak
  • 334,560
  • 70
  • 407
  • 495
7

number 3 is also considered relative. number 4 is absolute, but lacks the protocol. This is useful, if you want to be able to access the same URL using HTTP and HTTPS.

Absolute URLs specify the location of a Web page in full, and work identically no matter where in the world you are.

Relative URLs are context-sensitive, giving a path with respect to your current location.

Canavar
  • 47,715
  • 17
  • 91
  • 122
Jose Basilio
  • 50,714
  • 13
  • 121
  • 117
1

Type three is root-relative.

Dunno about 4.

Anthony
  • 7,086
  • 1
  • 21
  • 22
0

Absolute Url gives out directly the location of the file/document you are looking for. example:"http:/www.otagasue.com/images/coolpics.jpg" Relative Urls normally points a file/document in relation ti the current location of the file.unlike absolute thet are short urls referring to root directory example"...otagasue/pica.jpg"

frm otaga.

  • This does not seem to answer the question. Could you refer to the example the OP has given? – Uooo Aug 09 '13 at 07:57