RFC 1808
Relative Uniform Resource Locators
RFC 1808: Relative Uniform Resource Locators ๐
okay bestie, here's the tea ๐ซถ This one is by R. Fielding from UC Irvine, it's a Standards Track doc, and it's dated June 1995. Its title block doesn't list anything it obsoletes or updates, so there's nothing extra to chase down ๐
Status of this Memo โจ
okay, the boring-but-important bit first ๐ This document specifies an Internet standards track protocol for the Internet community, and it's literally asking people to discuss it and send suggestions for improvements ๐ If you want the current standardization state and status of this protocol, go check the current edition of the "Internet Official Protocol Standards" (STD 1). Distribution of this memo is unlimited ๐
Abstract ๐ฆ
a Uniform Resource Locator (URL) is a super compact way of writing down the location and access method for a resource on the Internet ๐ง When a URL is embedded in a base document, its absolute form can carry a ton of info that's already known from how the base document was retrieved, like the scheme, network location, and parts of the url-path ๐ If the base URL is well-defined and the parser (human or machine) knows it, it's so useful to embed URL references that just inherit that context instead of repeating it every single time. This document defines the syntax and semantics for these Relative Uniform Resource Locators ๐
1. Introduction โจ
this doc is all about "relative" Uniform Resource Locators (relative URLs), which are a compact way of describing where a resource is, relative to an absolute base URL ๐ It's a companion to RFC 1738, "Uniform Resource Locators (URL)" [2], which specifies the syntax and semantics of absolute URLs.
a super common move is to embed URLs inside a document (the "base" document) so you can point at other Internet-accessible resources ๐ In hypertext docs, URLs are the identifiers for where your link destinations are, so it's literally the whole point ๐
absolute URLs are packed with info that might already be known from how the base document got retrieved, like the scheme, network location, and parts of the URL path ๐ฆ When the base URL is well-defined and known, it's useful to embed a URL reference that inherits all of that instead of re-typing it in every instance. Relative URLs are also handy in data-entry dialogs, because they cut down on how many characters you need to describe a location โ๏ธ
also, it's really often the case that a group or "tree" of documents was built for one common purpose, and the vast majority of URLs in there point to spots inside the tree instead of outside of it ๐ณ Same energy for documents at a particular Internet site: they're way more likely to refer to other resources at that site than to resources at remote sites ๐
relative addressing lets document trees be partially independent of their location and access scheme ๐ฆ For instance, one set of hypertext docs can be accessed and traversed through each of the "file", "http", and "ftp" schemes, as long as the docs refer to each other with relative URLs. You can even move a whole document tree around without changing any of the embedded URLs. The World-Wide Web has proven that being able to do relative referencing is necessary for embedded URLs to stay usable long-term ๐ฅน
2. Relative URL Syntax ๐ง
okay, this is where the real syntax lives ๐ค The syntax for relative URLs is a shortened form of the one for absolute URLs [2]. Some prefix of the URL is missing, and certain path components ("." and "..") have a special meaning when you're interpreting a relative path. Because a relative URL can show up in any context that could hold an absolute URL, systems that support relative URLs have to be able to recognize them as part of the URL parsing process ๐
this doc doesn't try to define the overall URL syntax, but we still need to talk about some of it to explain how relative URLs get parsed โจ The key thing is that base documents can only make use of relative URLs when their base URL fits the generic-RL syntax below. Some URL schemes don't need that generic-RL syntax, but it's assumed that any document with a relative reference does have a base URL that obeys it. In other words, relative URLs can't be used within documents that have unsuitable base URLs ๐ซ
2.1. URL Syntactic Components ๐
the URL syntax depends on the scheme. Some schemes use reserved characters like "?" and ";" to indicate special components, while others just treat them as part of the path. BUT there's enough uniformity in how URLs get used that a parser can resolve relative URLs based on one single, generic-RL syntax ๐ซง This generic-RL syntax has six components:
<scheme>://<net_loc>/<path>;<params>?<query>#<fragment>
each one, except <scheme>, can be absent from a particular URL ๐ซ Here's how they're defined (the complete BNF is in Section 2.2):
scheme ":" ::= scheme name, as per Section 2.1 of RFC 1738 [2].
"//" net_loc ::= network location and login information, as per
Section 3.1 of RFC 1738 [2].
"/" path ::= URL path, as per Section 3.1 of RFC 1738 [2].
";" params ::= object parameters (e.g., ";type=a" as in
Section 3.2.2 of RFC 1738 [2]).
"?" query ::= query information, as per Section 3.3 of
RFC 1738 [2].
"#" fragment ::= fragment identifier.
quick note: the fragment identifier (and the "#" that comes before it) is not considered part of the URL ๐ But since it's commonly used in the same string context as a URL, a parser has to be able to recognize the fragment when it's present and set it aside as part of the parsing process ๐งน
the order of the components matters ๐ If both <params> and <query> are present, the <query> info has to occur after the <params>.
2.2. BNF for Relative URLs ๐
this is a BNF-like description of the Relative Uniform Resource Locator syntax, using the conventions of RFC 822 [5], except that "|" is used to designate alternatives. Quick cheat sheet: literals are quoted with "", parentheses "(" and ")" group elements, optional elements are enclosed in [brackets], and you can put <n>* in front of an element to mean n or more repetitions of the element that follows it, with n defaulting to 0 ๐
this BNF also describes the generic-RL syntax for valid base URLs. Heads up though: this is different from the URL syntax in RFC 1738 [2], because all schemes are required to use a single set of reserved characters and use them consistently within the major URL components ๐ซข
URL = ( absoluteURL | relativeURL ) [ "#" fragment ]
absoluteURL = generic-RL | ( scheme ":" *( uchar | reserved ) )
generic-RL = scheme ":" relativeURL
relativeURL = net_path | abs_path | rel_path
net_path = "//" net_loc [ abs_path ]
abs_path = "/" rel_path
rel_path = [ path ] [ ";" params ] [ "?" query ]
path = fsegment *( "/" segment )
fsegment = 1*pchar
segment = *pchar
params = param *( ";" param )
param = *( pchar | "/" )
scheme = 1*( alpha | digit | "+" | "-" | "." )
net_loc = *( pchar | ";" | "?" )
query = *( uchar | reserved )
fragment = *( uchar | reserved )
pchar = uchar | ":" | "@" | "&" | "="
uchar = unreserved | escape
unreserved = alpha | digit | safe | extra
escape = "%" hex hex
hex = digit | "A" | "B" | "C" | "D" | "E" | "F" |
"a" | "b" | "c" | "d" | "e" | "f"
alpha = lowalpha | hialpha
lowalpha = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" |
"j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" |
"s" | "t" | "u" | "v" | "w" | "x" | "y" | "z"
hialpha = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" |
"J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" |
"S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z"
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" |
"8" | "9"
safe = "$" | "-" | "_" | "." | "+"
extra = "!" | "*" | "'" | "(" | ")" | ","
national = "{" | "}" | "|" | "\" | "^" | "~" | "[" | "]" | "`"
reserved = ";" | "/" | "?" | ":" | "@" | "&" | "="
punctuation = "<" | ">" | "#" | "%" | <">
2.3. Specific Schemes and their Syntactic Categories ๐งฉ
each URL scheme has its own rules about whether the syntactic components from Sections 2.1 and 2.2 are present or absent. On top of that, some schemes are never appropriate for relative URLs. But since relative URLs will only be used in contexts where they're actually useful, the resolution process can ignore these scheme-specific differences ๐
in this section we only include as examples the schemes that have a defined URL syntax in RFC 1738 [2]. These schemes are never used with relative URLs:
mailto Electronic Mail
news USENET news
telnet TELNET Protocol for Interactive Sessions
some URL schemes allow reserved characters to be used for purposes outside the generic-RL syntax above. Honestly though, that's pretty rare ๐คท Relative URLs can be used with these schemes whenever the applicable base URL follows the generic-RL syntax:
gopher Gopher and Gopher+ Protocols
prospero Prospero Directory Service
wais Wide Area Information Servers Protocol
gopher URL users should know that gopher-type information is almost always included at the start of what would be the generic-RL path ๐ฟ๏ธ If it's present, that type info stops relative-path references from pointing to documents with differing gopher-types.
finally, the following schemes can always be parsed using the generic-RL syntax. That doesn't necessarily mean relative URLs will be useful with them, though. That decision is left to the system implementation and the author of the base document ๐ค
file Host-specific Files
ftp File Transfer Protocol
http Hypertext Transfer Protocol
nntp USENET news using NNTP access
NOTE: Section 5 of RFC 1738 says the question-mark character ("?") is allowed in an ftp or file path segment. However, this isn't true in practice, and it's believed to be an error in the RFC ๐ญ Similarly, RFC 1738 allows the reserved character semicolon (";") within an http path segment, but it doesn't define its semantics. The correct semantics are the ones this document defines for <params>.
we recommend that new schemes be designed to be parsable via the generic-RL syntax if they're meant to be used with relative URLs ๐ A description of the allowed relative forms should be included when a new scheme is registered, as per Section 4 of RFC 1738 [2].
2.4. Parsing a URL โจ
okay so parsing is basically the step where you chop a URL into its little pieces ๐ช๐ and it's SO useful bc it makes the generic-RL syntax from Section 2.2 way clearer, and it also sets up the resolving algorithm we get to in Section 4 ๐ฆ. this section walks through the rules for breaking down any URL (relative or absolute) into the component parts from Section 2.1. the rules assume the URL has already been pulled out of whatever text it was sitting in and copied into a "parse string" ๐. and the rules are listed in the order the parser applies them, so no skipping ahead bestie ๐
2.4.1. Parsing the Fragment Identifier ๐งฉ
if the parse string has a crosshatch # character in it, then whatever comes after the first (left-most) crosshatch #, all the way to the end of the parse string, is the <fragment> identifier ๐ธ. if the crosshatch is the very last character, or there's no crosshatch at all, the fragment identifier is empty. then the matched substring, crosshatch included, gets yeeted out of the parse string before you keep going ๐๏ธ
ngl the fragment is not considered part of the URL ๐ but since it's usually stuck right onto the URL, parsers must be able to recognize and set aside fragment identifiers as part of the process. main character energy for sure ๐
2.4.2. Parsing the Scheme ๐
if the parse string has a colon : after the first character and before any character that isn't allowed in a scheme name (so anything that isn't alphanumeric, plus +, period ., or hyphen -) ๐ซ, then the <scheme> of the URL is everything up to but not including that first colon. those characters and the colon get removed from the parse string before continuing โ๏ธ
2.4.3. Parsing the Network Location/Login ๐
if the parse string begins with a double-slash //, then the substring of characters after the double-slash, up to but not including the next slash / character, is the network location/login (<net_loc>) of the URL ๐ป. if no trailing slash / is present, the entire remaining parse string gets assigned to <net_loc>. the double-slash and <net_loc> are then removed from the parse string before continuing ๐ซง
2.4.4. Parsing the Query Information โ
if the parse string contains a question mark ? character, then the substring after the first (left-most) question mark ?, up to the end of the parse string, is the <query> information ๐. if the question mark is the last character, or there's no question mark at all, the query information is empty. the matched substring, question mark included, gets removed from the parse string before continuing.
2.4.5. Parsing the Parameters ๐
if the parse string has a semicolon ; character, then the substring after the first (left-most) semicolon ;, up to the end of the parse string, is the parameters (<params>) โจ. if the semicolon is the last character, or there isn't one, <params> is empty. the matched substring, semicolon included, is removed from the parse string before continuing.
2.4.6. Parsing the Path ๐ค๏ธ
after all the steps above, whatever's left of the parse string is the URL <path> plus the slash / that might come right before it ๐ซถ. even though that initial slash isn't technically part of the URL path, the parser must remember whether or not it was there, so later processes can tell relative and absolute paths apart. the usual move is just to keep that preceding slash stuck to the path, and honestly that's iconic ๐
3. Establishing a Base URL ๐บ๏ธ
okay so the term "relative URL" implies there's some absolute "base URL" that the relative reference gets applied against ๐งญ. the base URL is literally necessary to define what any embedded relative URLs even mean, bc without it a relative reference is meaningless ๐ญ. so for relative URLs to be usable inside a document, the base URL of that document has to be known to the parser.
there are four ways to set a document's base URL, listed in order of precedence (aka which one wins ๐). think of precedence like layers ๐ง , where the innermost defined base URL has the highest precedence. picture it like this:
.----------------------------------------------------------.
| .----------------------------------------------------. |
| | .----------------------------------------------. | |
| | | .----------------------------------------. | | |
| | | | (3.1) Base URL embedded in the | | | |
| | | | document's content | | | |
| | | `----------------------------------------' | | |
| | | (3.2) Base URL of the encapsulating entity | | |
| | | (message, document, or none). | | |
| | `----------------------------------------------' | |
| | (3.3) URL used to retrieve the entity | |
| `----------------------------------------------------' |
| (3.4) Base URL = "" (undefined) |
`----------------------------------------------------------'
3.1. Base URL within Document Content ๐
within certain document media types, the base URL can be embedded right inside the content so a parser can grab it easily ๐. this is useful for descriptive docs, like tables of content, that might get sent to people through protocols other than their usual retrieval context (e.g., E-Mail or USENET news) ๐ฌ.
it's beyond the scope of this document to spell out how the base URL gets embedded for each media type ๐. user agents handling those media types are assumed to get the right syntax from that media type's spec. an example of how to embed a base URL in the Hypertext Markup Language (HTML) [3] is in an Appendix (Section 10) ๐.
messages are considered composite documents ๐. the base URL of a message can be specified within its message headers (or equivalent tagged metainformation). for protocols that use message headers like the ones in RFC 822 [5], we recommend the header be formatted like this:
base-header = "Base" ":" "<URL:" absoluteURL ">"
"Base" is case-insensitive, and any whitespace (including the kind used for line folding) inside the angle brackets gets ignored ๐ซง. for example, this header field:
Base: <URL:http://www.ics.uci.edu/Test/a/b/c>
would indicate that the base URL for that message is the string "http://www.ics.uci.edu/Test/a/b/c" ๐ฆ. the base URL for a message serves as the base for any relative URLs within the message headers and the default base URL for documents enclosed in the message, as we'll see in the next section ๐.
protocols that don't use RFC 822 message header syntax, but do let you include some form of tagged metainformation in messages, can define their own syntax for setting the base URL as part of a message ๐ ๏ธ.
3.2. Base URL from the Encapsulating Entity ๐
if no base URL is embedded, the base URL of a document is defined by the document's retrieval context ๐. for a document enclosed within another entity (like a message or another document), the retrieval context is that entity. so the default base URL of the document is the base URL of the entity it's encapsulated in ๐ช.
composite media types, like the "multipart/" and "message/" media types defined by MIME (RFC 1521, [4]), define a hierarchy of retrieval context for their enclosed documents ๐งบ. so the retrieval context of a component part is the base URL of the composite entity it's a part of. a composite entity can redefine the retrieval context of its component parts by including a base-header, and that redefinition applies recursively across a hierarchy of composite parts ๐. just note that this might not change the base URL of the components, since each component may include an embedded base URL or base-header that takes precedence over the retrieval context ๐.
3.3. Base URL from the Retrieval URL ๐ฐ๏ธ
if no base URL is embedded and the document isn't encapsulated within some other entity (e.g., it's the top level of a composite entity), then, if a URL was used to retrieve the base document, that URL shall be considered the base URL ๐ฏ. and if the retrieval was the result of a redirected request, the last URL used (the one that actually resulted in retrieving the document) is the base URL ๐.
3.4. Default Base URL ๐ซฅ
if none of the conditions described in Sections 3.1 -- 3.3 apply, then the base URL is considered to be the empty string, and all embedded URLs within that document are assumed to be absolute URLs ๐งฑ.
it is the responsibility of the distributor(s) of a document containing relative URLs to make sure the base URL for that document can be established. it must be emphasized that relative URLs cannot be used reliably in situations where the document's base URL is not well-defined ๐จ
4. Resolving Relative URLs โจ
okay bestie, this section gives us an example algorithm for resolving URLs when they might be relative, so the result is always a URL in absolute form ๐ฆ It can't promise the result matches what the original author meant, ngl, but it does guarantee that any valid URL (relative or absolute) can be consistently transformed into absolute form given a valid base URL ๐
The following steps are performed in order ๐
- Step 1: The base URL is established according to the rules of Section 3. If the base URL is the empty string (unknown), the embedded URL is interpreted as an absolute URL and we are done.
- Step 2: Both the base and embedded URLs are parsed into their component parts as described in Section 2.4.
- a) If the embedded URL is entirely empty, it inherits the entire base URL (i.e., is set equal to the base URL) and we are done.
- b) If the embedded URL starts with a scheme name, it is interpreted as an absolute URL and we are done.
- c) Otherwise, the embedded URL inherits the scheme of the base URL.
- Step 3: If the embedded URL's
<net_loc>is non-empty, we skip to Step 7. Otherwise, the embedded URL inherits the<net_loc>(if any) of the base URL. - Step 4: If the embedded URL path is preceded by a slash
/, the path is not relative and we skip to Step 7. - Step 5: If the embedded URL path is empty (and not preceded by a slash), then the embedded URL inherits the base URL path, and
- a) if the embedded URL's
<params>is non-empty, we skip to Step 7; otherwise, it inherits the<params>of the base URL (if any), and - b) if the embedded URL's
<query>is non-empty, we skip to Step 7; otherwise, it inherits the<query>of the base URL (if any) and we skip to Step 7.
- a) if the embedded URL's
- Step 6: The last segment of the base URL's path (anything following the rightmost slash
/, or the entire path if no slash is present) is removed, and the embedded URL's path is appended in its place. The following operations are then applied, in order, to the new path:- a) All occurrences of
./, where.is a complete path segment, are removed. - b) If the path ends with
.as a complete path segment, that.is removed. - c) All occurrences of
<segment>/../, where<segment>is a complete path segment not equal to.., are removed. Removal of these path segments is performed iteratively, removing the leftmost matching pattern on each iteration, until no matching pattern remains. - d) If the path ends with
<segment>/.., where<segment>is a complete path segment not equal to.., that<segment>/..is removed.
- a) All occurrences of
- Step 7: The resulting URL components, including any inherited from the base URL, are recombined to give the absolute form of the embedded URL.
Parameters, regardless of their purpose, do not form a part of the URL path and thus do not affect the resolving of relative paths. In particular, the presence or absence of the ;type=d parameter on an ftp URL does not affect the interpretation of paths relative to that URL. Fragment identifiers are only inherited from the base URL when the entire embedded URL is empty.
The above algorithm is intended to provide an example by which the output of implementations can be tested -- implementation of the algorithm itself is not required. For example, some systems may find it more efficient to implement Step 6 as a pair of segment stacks being merged, rather than as a series of string pattern matches.
5. Examples and Recommended Practice ๐ธ
Within an object with a well-defined base URL of
Base: <URL:http://a/b/c/d;p?q#f>
the relative URLs would be resolved as follows ๐
5.1. Normal Examples ๐ง
g:h = <URL:g:h>
g = <URL:http://a/b/c/g>
./g = <URL:http://a/b/c/g>
g/ = <URL:http://a/b/c/g/>
/g = <URL:http://a/g>
//g = <URL:http://g>
?y = <URL:http://a/b/c/d;p?y>
g?y = <URL:http://a/b/c/g?y>
g?y/./x = <URL:http://a/b/c/g?y/./x>
#s = <URL:http://a/b/c/d;p?q#s>
g#s = <URL:http://a/b/c/g#s>
g#s/./x = <URL:http://a/b/c/g#s/./x>
g?y#s = <URL:http://a/b/c/g?y#s>
;x = <URL:http://a/b/c/d;x>
g;x = <URL:http://a/b/c/g;x>
g;x?y#s = <URL:http://a/b/c/g;x?y#s>
. = <URL:http://a/b/c/>
./ = <URL:http://a/b/c/>
.. = <URL:http://a/b/>
../ = <URL:http://a/b/>
../g = <URL:http://a/b/g>
../.. = <URL:http://a/>
../../ = <URL:http://a/>
../../g = <URL:http://a/g>
5.2. Abnormal Examples ๐
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.
An empty reference resolves to the complete base URL:
<> = <URL:http://a/b/c/d;p?q#f>
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 <net_loc> of a URL.
../../../g = <URL:http://a/../g>
../../../../g = <URL:http://a/../../g>
Similarly, parsers MUST avoid treating "." and ".." as special when they are not complete components of a relative path.
/./g = <URL:http://a/./g>
/../g = <URL:http://a/../g>
g. = <URL:http://a/b/c/g.>
.g = <URL:http://a/b/c/.g>
g.. = <URL:http://a/b/c/g..>
..g = <URL:http://a/b/c/..g>
Less likely are cases where the relative URL uses unnecessary or nonsensical forms of the "." and ".." complete path segments.
./../g = <URL:http://a/b/g>
./g/. = <URL:http://a/b/c/g/>
g/./h = <URL:http://a/b/c/g/h>
g/../h = <URL:http://a/b/c/h>
Finally, some older parsers allow the scheme name to be present in a relative URL if it is the same as the base URL scheme. This is considered to be a loophole in prior specifications of partial URLs [1] and SHOULD be avoided by future parsers. ๐ โโ๏ธ
http:g = <URL:http:g>
http: = <URL:http:>
5.3. Recommended Practice ๐
Authors SHOULD be aware that path names which contain a colon ":" character cannot be used as the first component of a relative URL path (e.g., "this:that") because they will likely be mistaken for a scheme name. It is therefore necessary to precede such cases with other components (e.g., "./this:that"), or to escape the colon character (e.g., "this%3Athat"), in order for them to be correctly parsed. The former solution is preferred because it does not affect the absolute form of the URL.
There is an ambiguity in the semantics for the ftp URL scheme regarding the use of a trailing slash ("/") character and/or a parameter ;type=d to indicate a resource that is an ftp directory. If the result of retrieving that directory includes embedded relative URLs, it is necessary that the base URL path for that result include a trailing slash. For this reason, we recommend that the ;type=d parameter value not be used within contexts that allow relative URLs.
6. Security Considerations ๐จ
There are no security considerations in the use or parsing of relative URLs. However, once a relative URL has been resolved to its absolute form, the same security considerations apply as those described in RFC 1738 [2]. ๐ญ
7. Acknowledgements ๐ซถ
This work is derived from concepts introduced by Tim Berners-Lee and the World-Wide Web global information initiative. Relative URLs are described as "Partial URLs" in RFC 1630 [1]. That description was expanded for inclusion as an appendix for an early draft of RFC 1738, "Uniform Resource Locators (URL)" [2]. However, after further discussion, the URI-WG decided to specify Relative URLs separately from the primary URL draft.
This document is intended to fulfill the recommendations for Internet Resource Locators as stated in [6]. It has benefited greatly from the comments of all those participating in the URI-WG. Particular thanks go to Larry Masinter, Michael A. Dolan, Guido van Rossum, Dave Kristol, David Robinson, and Brad Barber for identifying problems/deficiencies in earlier drafts. ๐
8. References ๐
- [1] Berners-Lee, T., "Universal Resource Identifiers in WWW: A Unifying Syntax for the Expression of Names and Addresses of Objects on the Network as used in the World-Wide Web", RFC 1630, CERN, June 1994.
- [2] Berners-Lee, T., Masinter, L., and M. McCahill, Editors, "Uniform Resource Locators (URL)", RFC 1738, CERN, Xerox Corporation, University of Minnesota, December 1994.
- [3] Berners-Lee T., and D. Connolly, "HyperText Markup Language Specification -- 2.0", Work in Progress, MIT, HaL Computer Systems, February 1995.
<URL:http://www.ics.uci.edu/pub/ietf/html/> - [4] Borenstein, N., and N. Freed, "MIME (Multipurpose Internet Mail Extensions): Mechanisms for Specifying and Describing the Format of Internet Message Bodies", RFC 1521, Bellcore, Innosoft, September 1993.
- [5] Crocker, D., "Standard for the Format of ARPA Internet Text Messages", STD 11, RFC 822, UDEL, August 1982.
- [6] Kunze, J., "Functional Recommendations for Internet Resource Locators", RFC 1736, IS&T, UC Berkeley, February 1995.
9. Author's Address ๐ฎ
Roy T. Fielding
Department of Information and Computer Science
University of California
Irvine, CA 92717-3425
U.S.A.
Tel: +1 (714) 824-4049
Fax: +1 (714) 824-4056
EMail: fielding@ics.uci.edu
10. Appendix - Embedding the Base URL in HTML documents ๐
It is useful to consider an example of how the base URL of a document can be embedded within the document's content. In this appendix, we describe how documents written in the Hypertext Markup Language (HTML) [3] can include an embedded base URL. This appendix does not form a part of the relative URL specification and SHOULD NOT be considered as anything more than a descriptive example.
HTML defines a special element "BASE" which, when present in the "HEAD" portion of a document, signals that the parser SHOULD use the BASE element's "HREF" attribute as the base URL for resolving any relative URLs. The "HREF" attribute MUST be an absolute URL. Note that, in HTML, element and attribute names are case-insensitive. For example:
<!doctype html public "-//IETF//DTD HTML//EN">
<HTML><HEAD>
<TITLE>An example HTML document</TITLE>
<BASE href="http://www.ics.uci.edu/Test/a/b/c">
</HEAD><BODY>
... <A href="../x">a hypertext anchor</A> ...
</BODY></HTML>
A parser reading the example document SHOULD interpret the given relative URL "../x" as representing the absolute URL
<URL:http://www.ics.uci.edu/Test/a/x>
regardless of the context in which the example document was obtained. โจ
๐ฆ where this page comes from
- ietf: rfc1808 1995-06
- ๐ girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms