Skip to main content

5. Reference Resolution

This section describes the algorithm for resolving URI references into absolute form.

5.1. Establishing a Base URI

Resolution of relative references requires a base URI. The base URI can be established through various methods.

5.1.1. Base URI Embedded in Content

Mechanisms such as HTML's <base> tag can specify the base URI within content.

5.1.2. Base URI from the Encapsulating Entity

An encapsulating entity (such as a MIME message) may define the base URI.

5.1.3. Base URI from the Retrieval URI

If no other base URI is available, use the URI from which the document was retrieved.

5.1.4. Default Base URI

Applications may define a default base URI.

5.2. Relative Resolution

Pseudocode for the relative reference resolution algorithm:

if R.scheme is defined then
T.scheme = R.scheme
T.authority = R.authority
T.path = remove_dot_segments(R.path)
T.query = R.query
else
if R.authority is defined then
T.authority = R.authority
T.path = remove_dot_segments(R.path)
T.query = R.query
else
if R.path is empty then
T.path = Base.path
if R.query is defined then
T.query = R.query
else
T.query = Base.query
else
if R.path starts-with "/" then
T.path = remove_dot_segments(R.path)
else
T.path = merge(Base, R.path)
T.path = remove_dot_segments(T.path)
T.query = R.query
T.authority = Base.authority
T.scheme = Base.scheme
T.fragment = R.fragment

5.3. Component Recomposition

Recombine the resolved components into a URI string.

5.4. Reference Resolution Examples

Base URI: http://a/b/c/d;p?q

Relative ReferenceResolved Result
ghttp://a/b/c/g
./ghttp://a/b/c/g
g/http://a/b/c/g/
/ghttp://a/g
//ghttp://g
?yhttp://a/b/c/d;p?y
g?yhttp://a/b/c/g?y
#shttp://a/b/c/d;p?q#s
../ghttp://a/b/g
../../ghttp://a/g

Next Chapter: 6. Normalization and Comparison - URI normalization techniques