35

There are (at least) three ways to link to a resource:

  1. href="foo/bar.html"
  2. href="/foo/bar.html"
  3. href="http://example.com/foo/bar.html"

The first is a "relative url", no problem. But I've seen (2) and (3) both referred to as an "absolute url". Which is correctly termed an "absolute url", and what is the proper name of the other?

(Bonus points for references to relevant standards or other official documentation.)

Scott Stafford
  • 43,764
  • 28
  • 129
  • 177

7 Answers7

49

RFC 3986 defines Uniform Resource Identifiers.

A relative reference that begins with a single slash character is
termed an absolute-path reference. A relative reference that does
not begin with a slash character is termed a relative-path reference.

  1. href="foo/bar.html" is a relative reference, specifically a relative-path reference.
  2. href="/foo/bar.html" is a relative reference with an absolute path
  3. href="http://example.com/foo/bar.html" is an absolute URI
  4. href="//example.com/foo/bar.html" is a network-path reference

A relative reference that begins with two slash characters is termed a network-path reference; such references are rarely used.

Community
  • 1
  • 1
Jacob Krall
  • 28,341
  • 6
  • 66
  • 76
  • 4
    For #4, agreed that they're rarely used, but I'd say there is a very good use for them. Any content that is hosted in both HTTP and HTTPS on the same path would benefit from this - avoid the overhead of HTTPS when it's not needed, and use it on secure pages to avoid browser warnings. Scripts hosted on CDNs are a good example: ([see this post](http://stackoverflow.com/questions/3622598/https-and-external-cdn-hosted-files/3622615#3622615)) – Joe Enos Jul 01 '13 at 20:30
  • 2
    @JoeEnos I agree with you; that's a direct quote from the RFC. – Jacob Krall Jul 01 '13 at 22:51
  • 4
    Funny how a mere 4 years later, and `network-path references` are ubitquitous in CDN script references. – Scott Stafford May 11 '17 at 13:55
4

"Absolute URLs contain a great deal of information which may already be known from the context of the base document's retrieval, including the scheme, network location, and parts of the URL path."

https://www.rfc-editor.org/rfc/rfc1808

The number (2) is an absolute path, the (3) is an absolute URL.

Community
  • 1
  • 1
Lorenzo Marcon
  • 8,029
  • 5
  • 38
  • 63
2

I like the W3's description found here:

A URL is an absolute URL if resolving it results in the same output regardless of what it is resolved relative to, and that output is not a failure.

It doesn't bring up scheme, path, or any other concepts like that, but basically just says that the same input always brings the same output. You can only say that about #3.

I wouldn't get too caught up in the technicalities though - #2 is still absolute if your universe is the website. Also something like //example.com/foo/bar.html is absolute if your universe is the scheme. I think the word "absolute" in those cases is still meaningful from a developer's perspective.

Joe Enos
  • 39,478
  • 11
  • 80
  • 136
2

The term I've heard for #2 is "root relative". I believe this is a useful definition as its meaning is clear in the wording and readily distinguishes it from #1 and #3.

1

RFC 3986 (URI Generic Syntax) specifies in section 4.3. Absolute URI the following rule:

absolute-URI = scheme ":" hier-part [ "?" query ]

Therefore, #2 is not an absolute URI

Mormegil
  • 7,955
  • 4
  • 42
  • 77
1

I believe (2) is also a relateive URL and (3) is an absolute URL.

http://kb.iu.edu/data/abwp.html shows some examples.

On http://www.wisegeek.com/what-is-an-absolute-url.htm, it explains it as this:

"An absolute URL gives complete location information. It begins with http:// and continues, including every detail. This means that if the webmaster were to change the location of the original file, an absolute URL specification would find the image, while the relative URL specification would not."

Brian
  • 529
  • 2
  • 7
  • 17
  • I believe you're basically correct, but secondhand references like those are prone to contribute to the FUD, which is why I asked for references to authoritative sources. – Scott Stafford Jul 01 '13 at 15:25
1

Only #3 fits the definition of absolute URL. 1 & 2 are relative URLs.

A relative URL (defined in [RFC1808]) doesn't contain any protocol or machine information, and its path generally refers to an HTML document on the same machine as the current document. Relative URLs may contain relative path components (".." means the parent location) and may be fragment URLs. Source: http://www.w3.org/TR/WD-html40-970708/htmlweb.html

A URL is an absolute URL if resolving it results in the same output regardless of what it is resolved relative to, and that output is not a failure. Source: http://www.w3.org/TR/url/

Olivia
  • 36
  • 1