2 <TITLE>Examples of Resolving Relative URLs</TITLE>
3 <BASE href="http://a/b/c/d;p?q">
5 <H1>Examples of Resolving Relative URLs</H1>
7 This document has an embedded base URL of
9 Content-Base: http://a/b/c/d;p?q
11 the relative URLs should be resolved as shown below.
13 I will need your help testing the examples on multiple browsers.
14 What you need to do is point to the example anchor and compare it to the
15 resolved URL in your browser (most browsers have a feature by which you
16 can see the resolved URL at the bottom of the window/screen when the anchor
19 <H2>Tested Clients and Client Libraries</H2>
23 <DD>RFC 2396 (the right way to parse)
27 <DD>Mozilla/4.03 [en] (X11; U; SunOS 5.5 sun4u; Nav)
29 <DD>Lynx/2.7.1 libwww-FM/2.14
31 <DD>MSIE 3.01; Windows 95
33 <DD>NCSA_Mosaic/2.6 (X11;SunOS 4.1.2 sun4m) libwww/2.12
35 <DD>libwww-perl/5.14 [Martijn Koster]
38 <H2>Normal Examples</H2>
42 <a href="g:h">g:h</a> = g:h [R,X,2,3,4,5]
45 <a href="g">g</a> = http://a/b/c/g [R,X,1,2,3,4,5]
47 <a href="./g">./g</a> = http://a/b/c/g [R,X,1,2,3,4,5]
49 <a href="g/">g/</a> = http://a/b/c/g/ [R,X,1,2,3,4,5]
51 <a href="/g">/g</a> = http://a/g [R,X,1,2,3,4,5]
53 <a href="//g">//g</a> = http://g [R,X,1,2,3,4,5]
55 <a href="?y">?y</a> = http://a/b/c/?y [R,1,2,3,4]
56 http://a/b/c/d;p?y [X,5]
58 <a href="g?y">g?y</a> = http://a/b/c/g?y [R,X,1,2,3,4,5]
60 <a name="s" href="#s">#s</a> = (current document)#s [R,2,4]
61 http://a/b/c/d;p?q#s [X,1,3,5]
63 <a href="g#s">g#s</a> = http://a/b/c/g#s [R,X,1,2,3,4,5]
65 <a href="g?y#s">g?y#s</a> = http://a/b/c/g?y#s [R,X,1,2,3,4,5]
67 <a href=";x">;x</a> = http://a/b/c/;x [R,1,2,3,4]
68 http://a/b/c/d;x [X,5]
70 <a href="g;x">g;x</a> = http://a/b/c/g;x [R,X,1,2,3,4,5]
72 <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]
74 <a href=".">.</a> = http://a/b/c/ [R,X,2,5]
78 <a href="./">./</a> = http://a/b/c/ [R,X,1,2,3,4,5]
80 <a href="..">..</a> = http://a/b/ [R,X,2,5]
83 <a href="../">../</a> = http://a/b/ [R,X,1,2,3,4,5]
85 <a href="../g">../g</a> = http://a/b/g [R,X,1,2,3,4,5]
87 <a href="../..">../..</a> = http://a/ [R,X,2,5]
90 <a href="../../">../../</a> = http://a/ [R,X,1,2,3,4,5]
92 <a href="../../g">../../g</a> = http://a/g [R,X,1,2,3,4,5]
95 <H2>Abnormal Examples</H2>
97 Although the following abnormal examples are unlikely to occur in
98 normal practice, all URL parsers should be capable of resolving them
99 consistently. Each example uses the same base as above.<P>
101 An empty reference refers to the start of the current document.
103 <a href=""><></a> = (current document) [R,2,4]
104 http://a/b/c/d;p?q [X,3,5]
107 Parsers must be careful in handling the case where there are more
108 relative path ".." segments than there are hierarchical levels in the
109 base URL's path. Note that the ".." syntax cannot be used to change
110 the site component of a URL.
112 <a href="../../../g">../../../g</a> = http://a/../g [R,X,2,4,5]
115 <a href="../../../../g">../../../../g</a> = http://a/../../g [R,X,2,4,5]
118 In practice, some implementations strip leading relative symbolic
119 elements (".", "..") after applying a relative URL calculation, based
120 on the theory that compensating for obvious author errors is better
121 than allowing the request to fail. Thus, the above two references
122 will be interpreted as "http://a/g" by some implementations.
124 Similarly, parsers must avoid treating "." and ".." as special when
125 they are not complete components of a relative path.
127 <a href="/./g">/./g</a> = http://a/./g [R,X,2,3,4,5]
130 <a href="/../g">/../g</a> = http://a/../g [R,X,2,3,4,5]
133 <a href="g.">g.</a> = http://a/b/c/g. [R,X,1,2,3,4,5]
135 <a href=".g">.g</a> = http://a/b/c/.g [R,X,1,2,3,4,5]
137 <a href="g..">g..</a> = http://a/b/c/g.. [R,X,1,2,3,4,5]
139 <a href="..g">..g</a> = http://a/b/c/..g [R,X,1,2,3,4,5]
141 Less likely are cases where the relative URL uses unnecessary or
142 nonsensical forms of the "." and ".." complete path segments.
144 <a href="./../g">./../g</a> = http://a/b/g [R,X,1,2,5]
145 http://a/b/c/../g [3,4]
147 <a href="./g/.">./g/.</a> = http://a/b/c/g/ [R,X,2,5]
151 <a href="g/./h">g/./h</a> = http://a/b/c/g/h [R,X,1,2,3,4,5]
153 <a href="g/../h">g/../h</a> = http://a/b/c/h [R,X,1,2,3,4,5]
155 <a href="g;x=1/./y">g;x=1/./y</a> = http://a/b/c/g;x=1/y [R,1,2,3,4]
156 http://a/b/c/g;x=1/./y [X,5]
158 <a href="g;x=1/../y">g;x=1/../y</a> = http://a/b/c/y [R,1,2,3,4]
159 http://a/b/c/g;x=1/../y [X,5]
162 All client applications remove the query component from the base URL
163 before resolving relative URLs. However, some applications fail to
164 separate the reference's query and/or fragment components from a
165 relative path before merging it with the base path. This error is
166 rarely noticed, since typical usage of a fragment never includes the
167 hierarchy ("/") character, and the query component is not normally
168 used within relative references.
170 <a href="g?y/./x">g?y/./x</a> = http://a/b/c/g?y/./x [R,X,5]
171 http://a/b/c/g?y/x [1,2,3,4]
173 <a href="g?y/../x">g?y/../x</a> = http://a/b/c/g?y/../x [R,X,5]
174 http://a/b/c/x [1,2,3,4]
176 <a href="g#s/./x">g#s/./x</a> = http://a/b/c/g#s/./x [R,X,2,3,4,5]
177 http://a/b/c/g#s/x [1]
179 <a href="g#s/../x">g#s/../x</a> = http://a/b/c/g#s/../x [R,X,2,3,4,5]
182 Some parsers allow the scheme name to be present in a relative URI if
183 it is the same as the base URI scheme. This is considered to be a
184 loophole in prior specifications of partial URI [RFC1630]. Its use
187 <a href="http:g">http:g</a> = http:g [R,X,5]
188 | http://a/b/c/g [1,2,3,4] (ok for compat.)
190 <a href="http:">http:</a> = http: [R,X,5]
192 http://a/b/c/d;p?q [2,3,4]