1 |
wakaba |
1.1 |
Uniform Resource Identifiers Working Group R.T. Fielding |
2 |
|
|
INTERNET-DRAFT UC Irvine |
3 |
|
|
Expires April 28, 1995 October 28, 1994 |
4 |
|
|
|
5 |
|
|
|
6 |
|
|
Relative Uniform Resource Locators |
7 |
|
|
<draft-ietf-uri-relative-url-01.txt> |
8 |
|
|
|
9 |
|
|
|
10 |
|
|
Status of this Memo |
11 |
|
|
|
12 |
|
|
This document is an Internet-Draft. Internet-Drafts are working |
13 |
|
|
documents of the Internet Engineering Task Force (IETF), its areas, |
14 |
|
|
and its working groups. Note that other groups may also distribute |
15 |
|
|
working documents as Internet-Drafts. |
16 |
|
|
|
17 |
|
|
Internet-Drafts are draft documents valid for a maximum of six |
18 |
|
|
months and may be updated, replaced, or obsoleted by other |
19 |
|
|
documents at any time. It is inappropriate to use Internet- |
20 |
|
|
Drafts as reference material or to cite them other than as |
21 |
|
|
``work in progress.'' |
22 |
|
|
|
23 |
|
|
To learn the current status of any Internet-Draft, please check |
24 |
|
|
the ``1id-abstracts.txt'' listing contained in the Internet- |
25 |
|
|
Drafts Shadow Directories on ds.internic.net (US East Coast), |
26 |
|
|
nic.nordu.net (Europe), ftp.isi.edu (US West Coast), or |
27 |
|
|
munnari.oz.au (Pacific Rim). |
28 |
|
|
|
29 |
|
|
Distribution of this document is unlimited. Please send comments |
30 |
|
|
to the editor, Roy T. Fielding <fielding@ics.uci.edu>, or to the |
31 |
|
|
URI working group (URI-WG) of the Internet Engineering Task Force |
32 |
|
|
(IETF) at <uri@bunyip.com>. Discussions of the group are archived at |
33 |
|
|
<URL:http://www.acl.lanl.gov/URI/archive/uri-archive.index.html>. |
34 |
|
|
|
35 |
|
|
|
36 |
|
|
Abstract |
37 |
|
|
|
38 |
|
|
Uniform Resource Locators (URLs) are a compact representation of the |
39 |
|
|
location and access method for a resource available via the Internet. |
40 |
|
|
When embedded within a base document, a URL in its absolute form may |
41 |
|
|
contain a great deal of information which is already known from the |
42 |
|
|
context of that base document's retrieval, including the access |
43 |
|
|
scheme, network location, and parts of the url-path. In situations |
44 |
|
|
where the base URL is well-defined and known to the parser (human or |
45 |
|
|
machine), it is useful to be able to embed URL references which |
46 |
|
|
inherit that context rather than re-specifying it in every instance. |
47 |
|
|
This document defines the syntax and semantics for such Relative |
48 |
|
|
Uniform Resource Locators. |
49 |
|
|
|
50 |
|
|
|
51 |
|
|
1. Introduction |
52 |
|
|
|
53 |
|
|
This work is derived from concepts introduced by the World-Wide Web |
54 |
|
|
global information initiative, whose use of such objects dates from |
55 |
|
|
1990 and is described in "Universal Resource Identifiers in WWW", |
56 |
|
|
RFC 1630 [1]. This document is a companion to the Internet-Draft |
57 |
|
|
"Uniform Resource Locators (URL)" [2], which specifies the |
58 |
|
|
syntax and semantics of absolute URLs. A URL is "absolute" if it |
59 |
|
|
can be interpreted consistently and unambiguously, with global scope, |
60 |
|
|
independent of any other URL. |
61 |
|
|
|
62 |
|
|
This document describes the syntax and semantics for "relative" |
63 |
|
|
Uniform Resource Locators (relative URLs): a compact representation |
64 |
|
|
of the location and access method for a resource available via the |
65 |
|
|
Internet relative to an absolute base URL. The name space of |
66 |
|
|
relative URLs is a superset of that defined in [2] for Uniform |
67 |
|
|
Resource Locators, in that all absolute URLs can be interpreted |
68 |
|
|
consistently relative to any Internet-accessible resource. For the |
69 |
|
|
sake of clarity, however, this document will only term "relative" |
70 |
|
|
those URLs which obtain global scope only when interpreted relative |
71 |
|
|
to a separate base URL. |
72 |
|
|
|
73 |
|
|
A primary use for Uniform Resource Locators is to embed them within |
74 |
|
|
a document (referred to as the "base" document) for the purpose of |
75 |
|
|
identifying other Internet-accessible resources. This is |
76 |
|
|
particularly true of hypertext documents, where URLs can serve as |
77 |
|
|
the identifiers for hypertext link destinations. |
78 |
|
|
|
79 |
|
|
It is often the case that, where a group or "tree" of documents |
80 |
|
|
serves a common purpose, the vast majority of URLs within those |
81 |
|
|
documents point to locations within that tree rather than outside |
82 |
|
|
of it. Similarly, documents located at a particular Internet site |
83 |
|
|
are much more likely to refer to other resources at that site than |
84 |
|
|
to resources at remote sites. |
85 |
|
|
|
86 |
|
|
Absolute URLs contain a great deal of information which may already |
87 |
|
|
be known from the context of the base document's retrieval, |
88 |
|
|
including the access scheme, network location, and parts of the |
89 |
|
|
URL path. In situations where the base URL is well-defined and |
90 |
|
|
known to the parser (human or machine), it is useful to be able to |
91 |
|
|
embed a URL reference which inherits that context rather than |
92 |
|
|
re-specifying it within each instance. |
93 |
|
|
|
94 |
|
|
In addition to the space saved, relative addressing of URLs allows |
95 |
|
|
document trees to be partially independent of their location and/or |
96 |
|
|
access scheme. For instance, if they refer to each other using |
97 |
|
|
relative URLs, it is possible for a single set of documents to be |
98 |
|
|
simultaneously accessible and, if hypertext, traversable via each |
99 |
|
|
of the "file", "http", and "ftp" access schemes. Furthermore, |
100 |
|
|
document trees can be moved, as a whole, without changing any of |
101 |
|
|
the embedded URLs. Experience within the World-Wide Web has |
102 |
|
|
demonstrated that the ability to perform relative referencing is |
103 |
|
|
necessary for the long-term usability of embedded URLs. |
104 |
|
|
|
105 |
|
|
2. Relative URL Syntax |
106 |
|
|
|
107 |
|
|
The syntax for relative URLs is the same as that for absolute URLs |
108 |
|
|
[2], with the exception that portions of the URL may be missing, and |
109 |
|
|
certain path components ("." and "..") have a special meaning when |
110 |
|
|
interpreting a relative URL path. Although this document does not |
111 |
|
|
seek to define the overall URL syntax, some discussion of it is |
112 |
|
|
necessary in order to describe the parsing of relative URLs. |
113 |
|
|
|
114 |
|
|
2.1. URL Syntactic Components |
115 |
|
|
|
116 |
|
|
The relative form relies on a property of the URL syntax that |
117 |
|
|
certain characters ("/") and certain path segments ("..", ".") have |
118 |
|
|
a significance reserved for representing a hierarchical space. |
119 |
|
|
Additional reserved characters are sometimes used to separate the |
120 |
|
|
URL path from other components, including object parameters (";"), |
121 |
|
|
query information ("?"), and fragment identifiers ("#"). |
122 |
|
|
|
123 |
|
|
Like absolute URLs, relative URL syntax is dependent upon the access |
124 |
|
|
scheme. Some schemes use "?" and ";" to indicate special reserved |
125 |
|
|
components, while others just consider them to be part of the path. |
126 |
|
|
However, there is enough uniformity in the syntax to allow a parser |
127 |
|
|
to resolve relative URLs based upon a few syntactic categories. |
128 |
|
|
These categories are described in Section 2.3. |
129 |
|
|
|
130 |
|
|
In general, the relative URL syntax consists of six components: |
131 |
|
|
|
132 |
|
|
<scheme>://<net_loc>/<path>;<params>?<query>#<fragment> |
133 |
|
|
|
134 |
|
|
each of which may be absent or may be disallowed by a particular |
135 |
|
|
scheme. They are defined as follows (a complete BNF is provided in |
136 |
|
|
Section 2.2): |
137 |
|
|
|
138 |
|
|
scheme ":" ::= access scheme name, as per Section 2.1 of [2]. |
139 |
|
|
|
140 |
|
|
"//" net_loc ::= network location and login information, as per |
141 |
|
|
Section 3.1 of [2]. |
142 |
|
|
|
143 |
|
|
"/" path ::= URL path, as per Section 3.1 of [2]. |
144 |
|
|
|
145 |
|
|
";" params ::= object parameters (e.g. ";type=a" as in |
146 |
|
|
Section 3.2.2 of [2]). |
147 |
|
|
|
148 |
|
|
"?" query ::= query information, as per Section 3.3 of [2]. |
149 |
|
|
|
150 |
|
|
"#" fragment ::= fragment identifier (currently only used within |
151 |
|
|
the World-Wide Web initiative). |
152 |
|
|
|
153 |
|
|
The order of the components is important. If both <params> and |
154 |
|
|
<query> are present, the <query> information must occur after the |
155 |
|
|
<params>. Relative components are resolved from left-to-right, |
156 |
|
|
according to the rules given in Section 4. |
157 |
|
|
|
158 |
|
|
2.2. BNF for Relative URLs |
159 |
|
|
|
160 |
|
|
This is a BNF-like description of the Relative Uniform Resource |
161 |
|
|
Locator syntax, using the conventions of RFC 822 [7], except that |
162 |
|
|
"|" is used to designate alternatives, and brackets "[]" are used |
163 |
|
|
around optional or repeated elements. Briefly, literals are quoted |
164 |
|
|
with "", optional elements are enclosed in [brackets], and elements |
165 |
|
|
may be preceded with <n>* to designate n or more repetitions of the |
166 |
|
|
following element; n defaults to 0. |
167 |
|
|
|
168 |
|
|
Because relative URLs are parsed within the context of the base URL, |
169 |
|
|
this BNF is not sufficient to completely specify the allowed syntax |
170 |
|
|
within any given context. Section 2.4 describes a context-sensitive |
171 |
|
|
parsing algorithm which disambiguates the grammar. |
172 |
|
|
|
173 |
|
|
|
174 |
|
|
relativeURL = [ absoluteURL | location | abs_path | rel_path ] |
175 |
|
|
[ "#" fragment ] |
176 |
|
|
|
177 |
|
|
absoluteURL = scheme ":" [ location | abs_path | rel_path ] |
178 |
|
|
location = "//" net_loc [ "/" rel_path ] |
179 |
|
|
abs_path = "/" rel_path |
180 |
|
|
rel_path = [ path ] [ ";" params ] [ "?" query ] |
181 |
|
|
|
182 |
|
|
path = segment *[ "/" segment ] |
183 |
|
|
segment = *[ pchar | ";" ] |
184 |
|
|
|
185 |
|
|
params = param *[ ";" param ] |
186 |
|
|
param = *[ pchar | "/" ] |
187 |
|
|
|
188 |
|
|
scheme = 1*[ alpha | digit | "+" | "-" | "." ] |
189 |
|
|
net_loc = *[ pchar | ";" ] |
190 |
|
|
query = *[ uchar | reserved | "#" ] |
191 |
|
|
fragment = *[ uchar | reserved ] |
192 |
|
|
|
193 |
|
|
pchar = [ uchar | "?" | ":" | "@" | "&" | "=" | "#" ] |
194 |
|
|
uchar = unreserved | escape |
195 |
|
|
unreserved = alpha | digit | safe | extra | national |
196 |
|
|
|
197 |
|
|
escape = "%" hex hex |
198 |
|
|
hex = digit | "A" | "B" | "C" | "D" | "E" | "F" | |
199 |
|
|
"a" | "b" | "c" | "d" | "e" | "f" |
200 |
|
|
|
201 |
|
|
alpha = lowalpha | hialpha |
202 |
|
|
lowalpha = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | |
203 |
|
|
"j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | |
204 |
|
|
"s" | "t" | "u" | "v" | "w" | "x" | "y" | "z" |
205 |
|
|
hialpha = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | |
206 |
|
|
"J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | |
207 |
|
|
"S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z" |
208 |
|
|
|
209 |
|
|
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | |
210 |
|
|
"8" | "9" |
211 |
|
|
|
212 |
|
|
safe = "$" | "-" | "_" | "." | "+" |
213 |
|
|
extra = "!" | "*" | "'" | "(" | ")" | "," |
214 |
|
|
national = "{" | "}" | "|" | "\" | "^" | "~" | "[" | "]" | "`" |
215 |
|
|
reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" |
216 |
|
|
punctuation = "<" | ">" | "#" | "%" | <"> |
217 |
|
|
|
218 |
|
|
|
219 |
|
|
2.3. Specific Schemes and their Syntactic Categories |
220 |
|
|
|
221 |
|
|
Each URL access scheme has its own rules regarding the presence or |
222 |
|
|
absence of the syntactic components described in Section 2.1 and 2.2. |
223 |
|
|
However, there is enough commonality among the schemes to be able |
224 |
|
|
to group them into just a few categories. These categories are |
225 |
|
|
sufficiently general to allow new schemes to be added without |
226 |
|
|
substantial changes to the algorithm for resolving relative URLs. |
227 |
|
|
|
228 |
|
|
Within this section, we include as examples only those schemes |
229 |
|
|
which have a defined URL syntax in [2]. This includes: |
230 |
|
|
|
231 |
|
|
ftp File Transfer Protocol [3] |
232 |
|
|
http Hypertext Transfer Protocol [4] |
233 |
|
|
gopher Gopher and Gopher+ Protocols [5, 6] |
234 |
|
|
mailto Electronic Mail [7] |
235 |
|
|
news USENET news [8] |
236 |
|
|
nntp USENET news using NNTP access [9] |
237 |
|
|
telnet TELNET Protocol for Interactive Sessions [10] |
238 |
|
|
wais Wide Area Information Servers Protocol [11,12] |
239 |
|
|
file Host-specific Files |
240 |
|
|
prospero Prospero Directory Service [13] |
241 |
|
|
|
242 |
|
|
It is recommended that new schemes include a description of their |
243 |
|
|
membership in the following categories when they are registered, |
244 |
|
|
as per Section 4 of [2]. Membership in the five categories is |
245 |
|
|
described in terms of named sets: Uses-Netloc, Non-Hierarchical, |
246 |
|
|
Uses-Params, Uses-Query, and Uses-Fragment. |
247 |
|
|
|
248 |
|
|
2.3.1 The Uses-Netloc Set |
249 |
|
|
|
250 |
|
|
The Uses-Netloc set includes those access schemes which use the |
251 |
|
|
Common Internet Scheme Syntax described in Section 3.1 of [2], where |
252 |
|
|
the network location and/or login information starts with a |
253 |
|
|
double-slash "//" to indicate its presence, and continues until the |
254 |
|
|
following slash "/", if any. |
255 |
|
|
|
256 |
|
|
Uses-Netloc = {ftp, http, gopher, nntp, telnet, wais, |
257 |
|
|
file, prospero} |
258 |
|
|
|
259 |
|
|
2.3.2 The Non-Hierarchical Set |
260 |
|
|
|
261 |
|
|
The Non-Hierarchical set includes those access schemes which do not |
262 |
|
|
use "/" to indicate hierarchical segments in the URL path. |
263 |
|
|
|
264 |
|
|
Non-Hierarchical = {gopher, wais, mailto, news, telnet, prospero} |
265 |
|
|
|
266 |
|
|
When resolving relative paths for schemes not in the Non-Hierarchical |
267 |
|
|
set, the complete path segments ".." and "." have a significance |
268 |
|
|
reserved for representing the path hierarchy, indicating up-one-level |
269 |
|
|
and current-level, respectively. |
270 |
|
|
|
271 |
|
|
2.3.3 The Uses-Params Set |
272 |
|
|
|
273 |
|
|
The Uses-Params set includes those access schemes which allow the |
274 |
|
|
semicolon ";" character to separate object parameters from the |
275 |
|
|
URL path. There may be more than one parameter, each being |
276 |
|
|
separated by a semicolon ";". |
277 |
|
|
|
278 |
|
|
Uses-Params = {ftp, http, prospero} |
279 |
|
|
|
280 |
|
|
2.3.4 The Uses-Query Set |
281 |
|
|
|
282 |
|
|
The Uses-Query set includes those access schemes which allow the |
283 |
|
|
question mark "?" character to separate query information from the |
284 |
|
|
URL path. |
285 |
|
|
|
286 |
|
|
Uses-Query = {http, wais} |
287 |
|
|
|
288 |
|
|
2.3.5 The Uses-Fragment Set |
289 |
|
|
|
290 |
|
|
The Uses-Fragment set includes those access schemes which allow the |
291 |
|
|
crosshatch "#" character to separate a fragment identifier from |
292 |
|
|
the rest of the URL. Within systems that use fragment identifiers, |
293 |
|
|
|
294 |
|
|
Uses-Fragment = {ftp, http, gopher, news, nntp, wais, |
295 |
|
|
file, prospero} |
296 |
|
|
|
297 |
|
|
Unlike the other sets, however, the fragment identifier is only |
298 |
|
|
reserved within systems which use it. Outside of those systems, |
299 |
|
|
Uses-Fragment is equal to the empty set. |
300 |
|
|
|
301 |
|
|
2.3.6. Summary of Categories by Scheme |
302 |
|
|
|
303 |
|
|
Uses- Non-Hier Uses- Uses- Uses- |
304 |
|
|
Netloc archical Params Query Fragment |
305 |
|
|
.--------------------------------------------. |
306 |
|
|
ftp | XXXX | | XXXX | | XXXX | |
307 |
|
|
http | XXXX | | XXXX | XXXX | XXXX | |
308 |
|
|
gopher | XXXX | XXXX | | | XXXX | |
309 |
|
|
mailto | | XXXX | | | | |
310 |
|
|
news | | XXXX | | | XXXX | |
311 |
|
|
nntp | XXXX | | | | XXXX | |
312 |
|
|
telnet | XXXX | XXXX | | | | |
313 |
|
|
wais | XXXX | XXXX | | XXXX | XXXX | |
314 |
|
|
file | XXXX | | | | XXXX | |
315 |
|
|
prospero | XXXX | XXXX | XXXX | | XXXX | |
316 |
|
|
`--------------------------------------------' |
317 |
|
|
|
318 |
|
|
2.4. Parsing a URL |
319 |
|
|
|
320 |
|
|
An accepted method for parsing URLs is necessary to disambiguate the |
321 |
|
|
relative URL syntax of Section 2.2 and to describe the algorithm for |
322 |
|
|
resolving relative URLs presented in Section 4. This section |
323 |
|
|
describes the parsing rules for breaking down a URL (relative or |
324 |
|
|
absolute) into the component parts described in Section 2.1. The |
325 |
|
|
rules assume that the URL has already been separated from any |
326 |
|
|
surrounding text and copied to a "parse string". The rules are |
327 |
|
|
listed in the order in which they must be applied by the parser. |
328 |
|
|
|
329 |
|
|
2.4.1. Parsing the Scheme |
330 |
|
|
|
331 |
|
|
If the parse string contains a colon ":" after the first character |
332 |
|
|
and before any characters not allowed as part of a scheme name |
333 |
|
|
(i.e. any not an alphanumeric, plus "+", period ".", or hyphen "-"), |
334 |
|
|
the scheme of the URL is the substring of characters up to but not |
335 |
|
|
including the first colon. These characters and the colon are then |
336 |
|
|
removed from the parse string before continuing. |
337 |
|
|
|
338 |
|
|
2.4.2. Parsing the Fragment Identifier |
339 |
|
|
|
340 |
|
|
If the scheme is not a member of the Uses-Fragment set, this section |
341 |
|
|
is skipped. |
342 |
|
|
|
343 |
|
|
If the parse string contains a crosshatch "#" character, then the |
344 |
|
|
substring after the last (right-most) crosshatch "#" and up to the |
345 |
|
|
end of the parse string is the fragment identifier. If the |
346 |
|
|
crosshatch is the last character, or no crosshatch is present, then |
347 |
|
|
the fragment identifier is empty. The matched substring, including |
348 |
|
|
the crosshatch character, is removed from the parse string before |
349 |
|
|
continuing. |
350 |
|
|
|
351 |
|
|
Note that the fragment identifier is not considered part of the URL. |
352 |
|
|
However, since it is often attached to the URL, parsers must be able |
353 |
|
|
to recognize and set aside fragment identifiers as part of the |
354 |
|
|
process. |
355 |
|
|
|
356 |
|
|
2.4.3. Parsing the Network Location/Login |
357 |
|
|
|
358 |
|
|
If the scheme is not a member of the Uses-Netloc set, this section |
359 |
|
|
is skipped. |
360 |
|
|
|
361 |
|
|
If the parse string begins with a double-slash "//", then the |
362 |
|
|
substring of characters after the double-slash and up to, but not |
363 |
|
|
including, the next slash "/" character is the network location/login |
364 |
|
|
(<net_loc>) of the URL. If no trailing slash "/" is present, the |
365 |
|
|
entire remaining parse string is assigned to <net_loc>. The |
366 |
|
|
double-slash and <net_loc> are removed from the parse string before |
367 |
|
|
continuing. |
368 |
|
|
|
369 |
|
|
2.4.4. Parsing the Query Information |
370 |
|
|
|
371 |
|
|
If the scheme is not a member of the Uses-Query set, this section |
372 |
|
|
is skipped. |
373 |
|
|
|
374 |
|
|
If the parse string contains a question mark "?" character, then the |
375 |
|
|
substring after the first (left-most) question mark "?" and up to the |
376 |
|
|
end of the parse string is the query information. If the question |
377 |
|
|
mark is the last character, or no question mark is present, then the |
378 |
|
|
query information is empty. The matched substring, including the |
379 |
|
|
question mark character, is removed from the parse string before |
380 |
|
|
continuing. |
381 |
|
|
|
382 |
|
|
2.4.5. Parsing the Parameters |
383 |
|
|
|
384 |
|
|
If the scheme is not a member of the Uses-Params set, this section |
385 |
|
|
is skipped. |
386 |
|
|
|
387 |
|
|
If the parse string contains a semicolon ";" character, then the |
388 |
|
|
substring after the first (left-most) semicolon ";" and up to the |
389 |
|
|
end of the parse string is the parameters (<params>). If the |
390 |
|
|
semicolon is the last character, or no semicolon is present, then |
391 |
|
|
<params> is empty. The matched substring, including the semicolon |
392 |
|
|
character, is removed from the parse string before continuing. |
393 |
|
|
|
394 |
|
|
2.4.6. Parsing the Path |
395 |
|
|
|
396 |
|
|
After the above steps, all that is left of the parse string is |
397 |
|
|
the URL path and the slash "/" that may precede it. Even though |
398 |
|
|
the initial slash is not part of the URL path, the parser must |
399 |
|
|
remember whether or not it was present so that later processes |
400 |
|
|
can differentiate between relative and absolute paths. Often this |
401 |
|
|
is done by simply storing the preceding slash along with the path. |
402 |
|
|
|
403 |
|
|
3. Establishing a Base URL |
404 |
|
|
|
405 |
|
|
In order for relative URLs to be usable within a base document, |
406 |
|
|
the absolute "base URL" of that document must be known to the |
407 |
|
|
parser. There are three methods for obtaining the base URL of |
408 |
|
|
a document, listed here in order of precedence. |
409 |
|
|
|
410 |
|
|
3.1. Base URL within Document Content |
411 |
|
|
|
412 |
|
|
Within certain document content-types, the base URL of the document |
413 |
|
|
can be embedded within the content itself such that it can be |
414 |
|
|
readily obtained by a parser. This can be useful for descriptive |
415 |
|
|
documents, such as tables of content, which may be transmitted to |
416 |
|
|
others through schemes which do not support relative addressing |
417 |
|
|
(e.g. E-Mail or USENET news). |
418 |
|
|
|
419 |
|
|
It is beyond the scope of this document to specify how, for each |
420 |
|
|
content-type, the base URL can be embedded. However, an example of |
421 |
|
|
how this is done for the Hypertext Markup Language (HTML) [14] is |
422 |
|
|
provided in an Appendix (Section 10). |
423 |
|
|
|
424 |
|
|
3.2. Base URL within Message Headers |
425 |
|
|
|
426 |
|
|
For access schemes which make use of message headers like those |
427 |
|
|
described in RFC 822 [7], a second method for identifying the base |
428 |
|
|
URL of a document is to include that URL in the message headers. |
429 |
|
|
It is recommended that the format of this header be: |
430 |
|
|
|
431 |
|
|
Base-URL: absoluteURL |
432 |
|
|
|
433 |
|
|
where "Base-URL" is case-insensitive. For example, |
434 |
|
|
|
435 |
|
|
Base-URL: http://www.ics.uci.edu/Test/a/b/c |
436 |
|
|
|
437 |
|
|
would indicate that any relative URLs found within the document |
438 |
|
|
should be parsed relative to <URL:http://www.ics.uci.edu/Test/a/b/c>. |
439 |
|
|
In situations where both an embedded base URL (as described in |
440 |
|
|
Section 3.1) and a "Base-URL" message header are present, the |
441 |
|
|
embedded base URL takes precedence. |
442 |
|
|
|
443 |
|
|
3.3. Base URL from the Retrieval Context |
444 |
|
|
|
445 |
|
|
If neither an embedded base URL nor a "Base-URL" message header |
446 |
|
|
is present, then, if a URL was used to retrieve the base document, |
447 |
|
|
that URL shall be considered the base URL. Note that if the |
448 |
|
|
retrieval was the result of a redirected request, the last URL used |
449 |
|
|
(i.e., that which resulted in the actual retrieval of the document) |
450 |
|
|
is the base URL. |
451 |
|
|
|
452 |
|
|
3.4. Default Base URL |
453 |
|
|
|
454 |
|
|
If none of the conditions described in Sections 3.1 -- 3.3 apply, |
455 |
|
|
then the base URL is considered to be the empty string and all |
456 |
|
|
embedded URLs within that document shall be interpreted as absolute. |
457 |
|
|
It is the responsibility of the distributor(s) of a document |
458 |
|
|
containing relative URLs to ensure that the base URL for that |
459 |
|
|
document can be established. It must be emphasized that relative |
460 |
|
|
URLs cannot be used reliably in situations where the object's base |
461 |
|
|
URL is not well-defined. |
462 |
|
|
|
463 |
|
|
4. Resolving Relative URLs |
464 |
|
|
|
465 |
|
|
This section describes an example algorithm for resolving URLs |
466 |
|
|
within a context in which the URLs may be relative, such that the |
467 |
|
|
result is always a URL in absolute form. Although this algorithm |
468 |
|
|
cannot guarantee that the resulting URL will equal that intended |
469 |
|
|
by the original author, it does guarantee that any valid URL |
470 |
|
|
(relative or absolute) can be consistently transformed to an |
471 |
|
|
absolute form given a valid base URL. |
472 |
|
|
|
473 |
|
|
The following steps are performed in order: |
474 |
|
|
|
475 |
|
|
Step 1: The base URL is established according to the rules of |
476 |
|
|
Section 3. |
477 |
|
|
|
478 |
|
|
Step 2: If the base URL is the empty string (unknown), the embedded |
479 |
|
|
URL is interpreted as an absolute URL and we are done. |
480 |
|
|
|
481 |
|
|
Step 3: Both the base and embedded URLs are parsed into their |
482 |
|
|
component parts as described in Section 2.4. |
483 |
|
|
|
484 |
|
|
a) If the embedded URL starts with a scheme name, it is |
485 |
|
|
interpreted as an absolute URL and we are done. |
486 |
|
|
|
487 |
|
|
b) Otherwise, the embedded URL inherits the scheme of |
488 |
|
|
the base URL. |
489 |
|
|
|
490 |
|
|
Step 4: If the scheme is a member of the Uses-Netloc set |
491 |
|
|
(Section 2.3.1), then |
492 |
|
|
|
493 |
|
|
a) If the embedded URL's <net_loc> is non-empty, we skip to |
494 |
|
|
Step 8. |
495 |
|
|
|
496 |
|
|
b) Otherwise, the embedded URL inherits the <net_loc> of the |
497 |
|
|
base URL. |
498 |
|
|
|
499 |
|
|
Step 5: If the embedded URL path is preceded by a slash "/", the |
500 |
|
|
path is not relative and we skip to Step 8. |
501 |
|
|
|
502 |
|
|
Step 6: If the embedded URL path is empty (and not preceded by a |
503 |
|
|
slash), then |
504 |
|
|
|
505 |
|
|
a) The embedded URL inherits the base URL path; and, |
506 |
|
|
|
507 |
|
|
b) If the embedded URL's <params> is empty, it |
508 |
|
|
inherits the <params> of the base URL (if any); and, |
509 |
|
|
|
510 |
|
|
c) If the embedded URL's <query> is empty, it inherits |
511 |
|
|
the <query> of the base URL (if any); and, |
512 |
|
|
|
513 |
|
|
d) We skip to Step 8. |
514 |
|
|
|
515 |
|
|
Step 7: The last path segment of the base URL's path (anything |
516 |
|
|
following the rightmost slash "/", or the entire path if no |
517 |
|
|
slash is present) is removed and the embedded URL's path is |
518 |
|
|
appended in its place. The following operations are |
519 |
|
|
then applied, in order, to the new URL path: |
520 |
|
|
|
521 |
|
|
a) All occurrences of "./", where "." is a complete path |
522 |
|
|
segment, are removed. |
523 |
|
|
|
524 |
|
|
b) If the URL path ends with "." as a complete path segment, |
525 |
|
|
that "." is removed. |
526 |
|
|
|
527 |
|
|
c) All occurrences of "<segment>/../", where <segment> and |
528 |
|
|
".." are complete path segments, are removed. Removal of |
529 |
|
|
these path segments is performed iteratively, removing the |
530 |
|
|
leftmost matching pattern on each iteration, until no |
531 |
|
|
matching pattern remains. |
532 |
|
|
|
533 |
|
|
d) If the URL path ends with "<segment>/..", that |
534 |
|
|
"<segment>/.." is removed. |
535 |
|
|
|
536 |
|
|
Step 8: The resulting URL components, including any inherited from |
537 |
|
|
the base URL, are recombined to give the absolute form of |
538 |
|
|
the embedded URL. |
539 |
|
|
|
540 |
|
|
Parameters, regardless of their purpose, do not form a part of the |
541 |
|
|
URL path and thus have no effect on the resolving of relative paths. |
542 |
|
|
In particular, the presence or absence of the ";type=d" parameter |
543 |
|
|
on an ftp URL has no effect on the interpretation of paths relative |
544 |
|
|
to that URL. Fragment identifiers are never inherited from the |
545 |
|
|
base URL. |
546 |
|
|
|
547 |
|
|
5. Examples and Recommended Practice |
548 |
|
|
|
549 |
|
|
Within an object with a well-defined base URL of |
550 |
|
|
|
551 |
|
|
<URL:http://a/b/c/d> |
552 |
|
|
|
553 |
|
|
the relative URLs would be resolved as follows: |
554 |
|
|
|
555 |
|
|
5.1. Normal Examples |
556 |
|
|
|
557 |
|
|
g:h = <URL:g:h> |
558 |
|
|
g = <URL:http://a/b/c/g> |
559 |
|
|
./g = <URL:http://a/b/c/g> |
560 |
|
|
g/ = <URL:http://a/b/c/g/> |
561 |
|
|
/g = <URL:http://a/g> |
562 |
|
|
//g = <URL:http://g> |
563 |
|
|
?y = <URL:http://a/b/c/d?y> |
564 |
|
|
g?y = <URL:http://a/b/c/g?y> |
565 |
|
|
g?y/./x = <URL:http://a/b/c/g?y/./x> |
566 |
|
|
. = <URL:http://a/b/c/> |
567 |
|
|
./ = <URL:http://a/b/c/> |
568 |
|
|
.. = <URL:http://a/b/> |
569 |
|
|
../ = <URL:http://a/b/> |
570 |
|
|
../g = <URL:http://a/b/g> |
571 |
|
|
../.. = <URL:http://a/> |
572 |
|
|
../../g = <URL:http://a/g> |
573 |
|
|
|
574 |
|
|
5.2. Abnormal Examples |
575 |
|
|
|
576 |
|
|
../../../g = <URL:http://a/../g> |
577 |
|
|
./../g = <URL:http://a/b/g> |
578 |
|
|
./g/. = <URL:http://a/b/c/g/> |
579 |
|
|
/./g = <URL:http://a/./g> |
580 |
|
|
g/./h = <URL:http://a/b/c/g/h> |
581 |
|
|
g/../h = <URL:http://a/b/c/h> |
582 |
|
|
http:g = <URL:http:g> |
583 |
|
|
http: = <URL:http:> |
584 |
|
|
|
585 |
|
|
Note that, although the abnormal examples are not likely to occur |
586 |
|
|
for a normal relative URL, all URL parsers should be capable of |
587 |
|
|
resolving them consistently. |
588 |
|
|
|
589 |
|
|
5.3. Recommended Practice |
590 |
|
|
|
591 |
|
|
Authors should be aware that path names which contain a colon |
592 |
|
|
":" character cannot be used as the first component of a relative |
593 |
|
|
URL path (e.g. "this:that") because they will likely be mistaken for |
594 |
|
|
a scheme name. It is therefore necessary to precede such cases with |
595 |
|
|
other components (e.g., "./this:that"), or to escape the colon |
596 |
|
|
character (e.g., "this%3Athat"), in order for them to be correctly |
597 |
|
|
parsed. The former solution is preferred because it has no effect |
598 |
|
|
on the absolute form of the URL. |
599 |
|
|
|
600 |
|
|
6. Security Considerations |
601 |
|
|
|
602 |
|
|
None. |
603 |
|
|
|
604 |
|
|
7. Acknowledgements |
605 |
|
|
|
606 |
|
|
This work is derived from concepts introduced by Tim Berners-Lee and |
607 |
|
|
the World-Wide Web global information initiative. Relative URLs are |
608 |
|
|
described as "Partial URLs" in RFC 1630 [1]. That description was |
609 |
|
|
expanded for inclusion as an appendix for the Internet-Draft |
610 |
|
|
"Uniform Resource Locators (URL)" [2]. However, after further |
611 |
|
|
discussion, the URI-WG decided to specify Relative URLs separately |
612 |
|
|
from the primary URL draft. |
613 |
|
|
|
614 |
|
|
This document is intended to fulfill the requirements for Internet |
615 |
|
|
Resource Locators as stated in [15]. It has benefited greatly from |
616 |
|
|
the comments of all those participating in the URI-WG. Particular |
617 |
|
|
thanks go to Larry Masinter, Michael A. Dolan, Guido van Rossum, and |
618 |
|
|
Dave Kristol for identifying problems/deficiencies in earlier drafts. |
619 |
|
|
|
620 |
|
|
8. References |
621 |
|
|
|
622 |
|
|
[1] Berners-Lee, T., "Universal Resource Identifiers in WWW: |
623 |
|
|
A Unifying Syntax for the Expression of Names and Addresses of |
624 |
|
|
Objects on the Network as used in the World-Wide Web", RFC 1630, |
625 |
|
|
<URL:ftp://ds.internic.net/rfc/rfc1630.txt>, June 1994. |
626 |
|
|
|
627 |
|
|
[2] Berners-Lee, T., Masinter, L., and McCahill, M., Editors, |
628 |
|
|
"Uniform Resource Locators (URL)", Internet-Draft (work in |
629 |
|
|
progress), <URL:ftp://ds.internic.net/internet-drafts/ |
630 |
|
|
draft-ietf-uri-url-08.txt>, October 1994. |
631 |
|
|
|
632 |
|
|
[3] Postel, J. and Reynolds, J.K., "File Transfer Protocol (FTP)", |
633 |
|
|
RFC 959, <URL:ftp://ds.internic.net/rfc/rfc959.txt>, October 1985. |
634 |
|
|
|
635 |
|
|
[4] Berners-Lee, T ., "Hypertext Transfer Protocol (HTTP)" , |
636 |
|
|
CERN, <URL:ftp://info.cern.ch/pub/www/doc/http-spec.txt.Z>, |
637 |
|
|
November 1993. |
638 |
|
|
|
639 |
|
|
[5] Anklesaria, F., McCahill, M., Lindner, P., Johnson, D., |
640 |
|
|
Torrey, D., and Alberti, B., "The Internet Gopher Protocol: |
641 |
|
|
A distributed document search and retrieval protocol", |
642 |
|
|
RFC 1436, <URL:ftp://ds.internic.net/rfc/rfc1436.txt>, |
643 |
|
|
March 1993. |
644 |
|
|
|
645 |
|
|
[6] Anklesaria, F., Lindner, P., McCahill, M., Torrey, D., |
646 |
|
|
Johnson, D., and Alberti, B., "Gopher+: Upward compatible |
647 |
|
|
enhancements to the Internet Gopher protocol", |
648 |
|
|
University of Minnesota, <URL:ftp://boombox.micro.umn.edu |
649 |
|
|
/pub/gopher/gopher_protocol/Gopher+/Gopher+.txt>, July 1993. |
650 |
|
|
|
651 |
|
|
[7] Crocker, D. H., "Standard for the Format of ARPA Internet Text |
652 |
|
|
Messages", RFC 822, <URL:ftp://ds.internic.net/rfc/rfc822.txt>, |
653 |
|
|
April 1982. |
654 |
|
|
|
655 |
|
|
[8] Horton, M. and Adams, R., "Standard For Interchange of USENET |
656 |
|
|
messages", RFC 1036, <URL:ftp://ds.internic.net/rfc/rfc1036.txt>, |
657 |
|
|
December 1987. |
658 |
|
|
|
659 |
|
|
[9] Kantor, B. and Lapsley, P., "Network News Transfer Protocol: |
660 |
|
|
A Proposed Standard for the Stream-Based Transmission of News", |
661 |
|
|
RFC977, <URL:ftp://ds.internic.net/rfc/rfc977.txt>, |
662 |
|
|
February 1986. |
663 |
|
|
|
664 |
|
|
[10] Postel, J. and Reynolds, J., "TELNET Protocol Specification", |
665 |
|
|
RFC 854, <URL:ftp://ds.internic.net/rfc/rfc854.txt>, May 1983. |
666 |
|
|
|
667 |
|
|
[11] Davis, F., Kahle, B., Morris, H., Salem, J., Shen, T., Wang, R., |
668 |
|
|
Sui, J., and Grinbaum, M., "WAIS Interface Protocol Prototype |
669 |
|
|
Functional Specification", (v1.5), Thinking Machines Corporation, |
670 |
|
|
<URL:ftp://quake.think.com/pub/wais/doc/protspec.txt>, |
671 |
|
|
April 1990. |
672 |
|
|
|
673 |
|
|
[12] St. Pierre, M, Fullton, J., Gamiel, K., Goldman, J., Kahle, B., |
674 |
|
|
Kunze, J., Morris, H., and Schiettecatte, F., |
675 |
|
|
"WAIS over Z39.50-1988", RFC 1625, |
676 |
|
|
<URL:ftp://ds.internic.net/rfc/rfc1625.txt>, June 1994. |
677 |
|
|
|
678 |
|
|
[13] Neuman, B.C., and Augart, S. "The Prospero Protocol", |
679 |
|
|
USC Information Sciences Institute, <URL: |
680 |
|
|
ftp://prospero.isi.edu/pub/prospero/doc/prospero-protocol.PS.Z>, |
681 |
|
|
June 1993. |
682 |
|
|
|
683 |
|
|
[14] Berners-Lee, T., Connolly, D., et al. "HyperText Markup Language |
684 |
|
|
Specification -- 2.0", HTML-WG draft (work in progress), |
685 |
|
|
<URL:ftp://www.ics.uci.edu/pub/ietf/html/>, October 1994. |
686 |
|
|
|
687 |
|
|
[15] Kunze, J., "Functional Requirements for Internet Resource |
688 |
|
|
Locators", Internet-Draft (work in progress), |
689 |
|
|
<URL:ftp://ds.internic.net/internet-drafts/ |
690 |
|
|
draft-ietf-uri-irl-fun-req-01.txt>, July 1994. |
691 |
|
|
|
692 |
|
|
9. Author's Address |
693 |
|
|
|
694 |
|
|
Roy T. Fielding |
695 |
|
|
Department of Information and Computer Science |
696 |
|
|
University of California |
697 |
|
|
Irvine, CA 92717-3425 |
698 |
|
|
U.S.A. |
699 |
|
|
|
700 |
|
|
Tel: +1 (714) 824-4049 |
701 |
|
|
Fax: +1 (714) 824-4056 |
702 |
|
|
Email: fielding@ics.uci.edu |
703 |
|
|
|
704 |
|
|
This Internet-Draft expires April 28, 1995. |
705 |
|
|
|
706 |
|
|
|
707 |
|
|
10. Appendix - Embedding the Base URL in HTML documents. |
708 |
|
|
|
709 |
|
|
It is useful to consider an example of how the base URL of a |
710 |
|
|
document can be embedded within the document's content. In this |
711 |
|
|
appendix, we describe how documents written in the Hypertext Markup |
712 |
|
|
Language (HTML) [14] can include an embedded base URL. This appendix |
713 |
|
|
does not form a part of the relative URL specification and should not |
714 |
|
|
be considered as anything more than a descriptive example. |
715 |
|
|
|
716 |
|
|
HTML defines a special element "BASE" which, when present in the |
717 |
|
|
"HEAD" portion of a document, signals that the parser should use |
718 |
|
|
the BASE element's "HREF" attribute as the base URL for resolving |
719 |
|
|
any relative URLs. The "HREF" attribute must be an absolute URL. |
720 |
|
|
Note that, in HTML, element and attribute names are case-insensitive. |
721 |
|
|
For example: |
722 |
|
|
|
723 |
|
|
<!doctype html public "-//IETF//DTD HTML//EN"> |
724 |
|
|
<HTML><HEAD> |
725 |
|
|
<TITLE>An example HTML document</TITLE> |
726 |
|
|
<BASE href="http://www.ics.uci.edu/Test/a/b/c"> |
727 |
|
|
</HEAD><BODY> |
728 |
|
|
... <A href="../x">a hypertext anchor</A> ... |
729 |
|
|
</BODY></HTML> |
730 |
|
|
|
731 |
|
|
A parser reading the example document should interpret the given |
732 |
|
|
relative URL "../x" as representing the absolute URL |
733 |
|
|
|
734 |
|
|
<URL:http://www.ics.uci.edu/Test/a/x> |
735 |
|
|
|
736 |
|
|
regardless of the context in which the example document was obtained. |
737 |
|
|
|