35

I am writing some documentation and I have a little vocabulary problem:

  1. http://www.example.com/en/public/img/logo.gif is called an "absolute" url, right?
  2. ../../public/img/logo.gif is called a "relative" url, right?
  3. so how do you call this: /en/public/img/logo.gif ?

Is it also considered an "absolute url", although without the protocol and domain parts?

Or is it considered a relative url, but relative to the root of the domain?

I googled a bit and some people categorize this as absolute, and others as relative.

What should I call it? A "semi-absolute url"? Or "semi-relative"? Is there another word?

unor
  • 87,575
  • 24
  • 195
  • 335
MiniQuark
  • 43,732
  • 33
  • 146
  • 174

5 Answers5

80

Here are the URL components:

http://www.example.com/en/public/img/logo.gif
\__/   \_____________/\_____________________/
 #1     #2             #3
  1. scheme/protocol
  2. host
  3. path

A URL is called an absolute URL if it begins with the scheme and scheme specific part (here // after http:). Anything else is a relative URL.

A URL path is called an absolute URL path if it begins with a /. Any other URL path is called a relative URL path.

Thus:

  • http://www.example.com/en/public/img/logo.gif is a absolute URL,
  • ../../public/img/logo.gif is a relative URL with a relative URL path and
  • /en/public/img/logo.gif is a relative URL with an absolute URL path.

Note: The current definition of URI (RFC 3986) is different from the old URL definition (RFC 1738 and RFC 1808).

The three examples with URI terms:

  • http://www.example.com/en/public/img/logo.gif is a URI,
  • ../../public/img/logo.gif is a relative reference with just a relative path and
  • /en/public/img/logo.gif is a relative reference with just an absolute path.
Community
  • 1
  • 1
Gumbo
  • 620,600
  • 104
  • 758
  • 828
  • I'm not sure if I understood that properly. Does that mean `//yolo.com` is considered an absolute url? – srph Jan 25 '16 at 11:28
  • @srph No. Only if it begins with the protocol/scheme it’s considered absolute. – Gumbo Jan 25 '16 at 17:58
  • But the browser seems to parse it properly. For example, `//yolo.com` would prepend the current scheme of the page. Is there any specific term, rfc, or reason why urls in browsers are parsed as absolute when prepended with `//`? – srph Jan 26 '16 at 07:27
  • 1
    @srph Relative URLs are always resolved to absolute ones based on the context they are used in. Have a look at the [section 5 of RFC 3986: *Reference Resolution*](http://tools.ietf.org/html/rfc3986#section-5) for additional information. – Gumbo Jan 26 '16 at 19:55
  • Nice answer, but who, in everyday conversation (or user-friendly documentation), is going to always refer to it as 'a relative reference with an absolute path'? MDN is usually a reliable source, but [they call it](https://developer.mozilla.org/en-US/docs/Learn/Common_questions/What_is_a_URL#examples_of_absolute_urls) an 'absolute URL' with an 'implicit domain name', which is even worse. For as long as I can remember, these were called *root-relative* links. The meaning is clear (it's relative to the root), and it's so much easier to say. – Kal Apr 28 '21 at 04:11
4

I have seen it called a root relative URL.

unor
  • 87,575
  • 24
  • 195
  • 335
  • Amazed that this answer got just one vote in over 11 years! If I were writing user-friendly documentation, that's *exactly* what I'd be calling it. – Kal Apr 28 '21 at 04:17
1

From the Microsoft's documentation about Absolute and Relative URLs

A URL specifies the location of a target stored on a local or networked computer. The target can be a file, directory, HTML page, image, program, and so on.

An absolute URL contains all the information necessary to locate a resource.

A relative URL locates a resource using an absolute URL as a starting point. In effect, the "complete URL" of the target is specified by concatenating the absolute and relative URLs.

An absolute URL uses the following format: scheme://server/path/resource

A relative URL typically consists only of the path, and optionally, the resource, but no scheme or server. The following tables define the individual parts of the complete URL format.

  • scheme - Specifies how the resource is to be accessed.

  • server - Specifies the name of the computer where the resource is located.

  • path - Specifies the sequence of directories leading to the target. If resource is omitted, the target is the last directory in path.

  • resource - If included, resource is the target, and is typically the name of a file. It may be a simple file, containing a single binary stream of bytes, or a structured document, containing one or more storages and binary streams of bytes.

Shamsiddin Saidov
  • 2,223
  • 4
  • 22
  • 35
0

It is sometimes called a virtual url, for example in SSI:

<!--#include virtual = "/lib/functions.js" -->
Guffa
  • 666,277
  • 106
  • 705
  • 986
0

Keep in mind just how many segments of the URL can be omited, making them relative (note: its all of them, just about). These are all valid URLs:

  • http://example.com/bar?baz
  • ?qoo=qalue
  • /bar2
  • dat/sly
  • //auth.example.com (most people are surprised by this one! Will use http or https, depending on the current resource)
  • #anchor
unor
  • 87,575
  • 24
  • 195
  • 335
ironfroggy
  • 7,654
  • 6
  • 31
  • 43