Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

195 lines (149 sloc) 7.493 kb
<HTML><HEAD>
<TITLE>Examples of Resolving Relative URLs</TITLE>
<BASE href="http://a/b/c/d;p?q">
</HEAD><BODY>
<H1>Examples of Resolving Relative URLs</H1>
This document has an embedded base URL of
<PRE>
Content-Base: http://a/b/c/d;p?q
</PRE>
the relative URLs should be resolved as shown below.
<P>
I will need your help testing the examples on multiple browsers.
What you need to do is point to the example anchor and compare it to the
resolved URL in your browser (most browsers have a feature by which you
can see the resolved URL at the bottom of the window/screen when the anchor
is active).
<H2>Tested Clients and Client Libraries</H2>
<DL COMPACT>
<DT>[R]
<DD>RFC 2396 (the right way to parse)
<DT>[X]
<DD>RFC 1808
<DT>[1]
<DD>Mozilla/4.03 [en] (X11; U; SunOS 5.5 sun4u; Nav)
<DT>[2]
<DD>Lynx/2.7.1 libwww-FM/2.14
<DT>[3]
<DD>MSIE 3.01; Windows 95
<DT>[4]
<DD>NCSA_Mosaic/2.6 (X11;SunOS 4.1.2 sun4m) libwww/2.12
<DT>[5]
<DD>libwww-perl/5.14 [Martijn Koster]
</DL>
<H2>Normal Examples</H2>
<PRE>
RESULTS from
<a href="g:h">g:h</a> = g:h [R,X,2,3,4,5]
http://a/b/c/g:h [1]
<a href="g">g</a> = http://a/b/c/g [R,X,1,2,3,4,5]
<a href="./g">./g</a> = http://a/b/c/g [R,X,1,2,3,4,5]
<a href="g/">g/</a> = http://a/b/c/g/ [R,X,1,2,3,4,5]
<a href="/g">/g</a> = http://a/g [R,X,1,2,3,4,5]
<a href="//g">//g</a> = http://g [R,X,1,2,3,4,5]
<a href="?y">?y</a> = http://a/b/c/?y [R,1,2,3,4]
http://a/b/c/d;p?y [X,5]
<a href="g?y">g?y</a> = http://a/b/c/g?y [R,X,1,2,3,4,5]
<a name="s" href="#s">#s</a> = (current document)#s [R,2,4]
http://a/b/c/d;p?q#s [X,1,3,5]
<a href="g#s">g#s</a> = http://a/b/c/g#s [R,X,1,2,3,4,5]
<a href="g?y#s">g?y#s</a> = http://a/b/c/g?y#s [R,X,1,2,3,4,5]
<a href=";x">;x</a> = http://a/b/c/;x [R,1,2,3,4]
http://a/b/c/d;x [X,5]
<a href="g;x">g;x</a> = http://a/b/c/g;x [R,X,1,2,3,4,5]
<a href="g;x?y#s">g;x?y#s</a> = http://a/b/c/g;x?y#s [R,X,1,2,3,4,5]
<a href=".">.</a> = http://a/b/c/ [R,X,2,5]
http://a/b/c/. [1]
http://a/b/c [3,4]
<a href="./">./</a> = http://a/b/c/ [R,X,1,2,3,4,5]
<a href="..">..</a> = http://a/b/ [R,X,2,5]
http://a/b [1,3,4]
<a href="../">../</a> = http://a/b/ [R,X,1,2,3,4,5]
<a href="../g">../g</a> = http://a/b/g [R,X,1,2,3,4,5]
<a href="../..">../..</a> = http://a/ [R,X,2,5]
http://a [1,3,4]
<a href="../../">../../</a> = http://a/ [R,X,1,2,3,4,5]
<a href="../../g">../../g</a> = http://a/g [R,X,1,2,3,4,5]
</PRE>
<H2>Abnormal Examples</H2>
Although the following abnormal examples are unlikely to occur in
normal practice, all URL parsers should be capable of resolving them
consistently. Each example uses the same base as above.<P>
An empty reference refers to the start of the current document.
<PRE>
<a href="">&lt;&gt;</a> = (current document) [R,2,4]
http://a/b/c/d;p?q [X,3,5]
http://a/b/c/ [1]
</PRE>
Parsers must be careful in handling the case where there are more
relative path ".." segments than there are hierarchical levels in the
base URL's path. Note that the ".." syntax cannot be used to change
the site component of a URL.
<PRE>
<a href="../../../g">../../../g</a> = http://a/../g [R,X,2,4,5]
http://a/g [R,1,3]
<a href="../../../../g">../../../../g</a> = http://a/../../g [R,X,2,4,5]
http://a/g [R,1,3]
</PRE>
In practice, some implementations strip leading relative symbolic
elements (".", "..") after applying a relative URL calculation, based
on the theory that compensating for obvious author errors is better
than allowing the request to fail. Thus, the above two references
will be interpreted as "http://a/g" by some implementations.
<P>
Similarly, parsers must avoid treating "." and ".." as special when
they are not complete components of a relative path.
<PRE>
<a href="/./g">/./g</a> = http://a/./g [R,X,2,3,4,5]
http://a/g [1]
<a href="/../g">/../g</a> = http://a/../g [R,X,2,3,4,5]
http://a/g [1]
<a href="g.">g.</a> = http://a/b/c/g. [R,X,1,2,3,4,5]
<a href=".g">.g</a> = http://a/b/c/.g [R,X,1,2,3,4,5]
<a href="g..">g..</a> = http://a/b/c/g.. [R,X,1,2,3,4,5]
<a href="..g">..g</a> = http://a/b/c/..g [R,X,1,2,3,4,5]
</PRE>
Less likely are cases where the relative URL uses unnecessary or
nonsensical forms of the "." and ".." complete path segments.
<PRE>
<a href="./../g">./../g</a> = http://a/b/g [R,X,1,2,5]
http://a/b/c/../g [3,4]
<a href="./g/.">./g/.</a> = http://a/b/c/g/ [R,X,2,5]
http://a/b/c/g/. [1]
http://a/b/c/g [3,4]
<a href="g/./h">g/./h</a> = http://a/b/c/g/h [R,X,1,2,3,4,5]
<a href="g/../h">g/../h</a> = http://a/b/c/h [R,X,1,2,3,4,5]
<a href="g;x=1/./y">g;x=1/./y</a> = http://a/b/c/g;x=1/y [R,1,2,3,4]
http://a/b/c/g;x=1/./y [X,5]
<a href="g;x=1/../y">g;x=1/../y</a> = http://a/b/c/y [R,1,2,3,4]
http://a/b/c/g;x=1/../y [X,5]
</PRE>
All client applications remove the query component from the base URL
before resolving relative URLs. However, some applications fail to
separate the reference's query and/or fragment components from a
relative path before merging it with the base path. This error is
rarely noticed, since typical usage of a fragment never includes the
hierarchy ("/") character, and the query component is not normally
used within relative references.
<PRE>
<a href="g?y/./x">g?y/./x</a> = http://a/b/c/g?y/./x [R,X,5]
http://a/b/c/g?y/x [1,2,3,4]
<a href="g?y/../x">g?y/../x</a> = http://a/b/c/g?y/../x [R,X,5]
http://a/b/c/x [1,2,3,4]
<a href="g#s/./x">g#s/./x</a> = http://a/b/c/g#s/./x [R,X,2,3,4,5]
http://a/b/c/g#s/x [1]
<a href="g#s/../x">g#s/../x</a> = http://a/b/c/g#s/../x [R,X,2,3,4,5]
http://a/b/c/x [1]
</PRE>
Some parsers allow the scheme name to be present in a relative URI if
it is the same as the base URI scheme. This is considered to be a
loophole in prior specifications of partial URI [RFC1630]. Its use
should be avoided.
<PRE>
<a href="http:g">http:g</a> = http:g [R,X,5]
| http://a/b/c/g [1,2,3,4] (ok for compat.)
<a href="http:">http:</a> = http: [R,X,5]
http://a/b/c/ [1]
http://a/b/c/d;p?q [2,3,4]
</PRE>
</BODY></HTML>
Jump to Line
Something went wrong with that request. Please try again.