next component separator or the end of the reference.
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 replacements.
Note: Some WWW client applications will fail to separate the
reference's query component from its path component before merging
the base and reference paths in step 6 above. This may result in
a loss of information if the query component contains the strings
"/../" or "/./".
Resolution examples are provided in Appendix C.
6. URI Normalization and Equivalence
In many cases, different URI strings may actually identify the
identical resource. For example, the host names used in URL are
actually case insensitive, and the URL <http://www.XEROX.com> is
equivalent to <http://www.xerox.com>. In general, the rules for
equivalence and definition of a normal form, if any, are scheme
dependent. When a scheme uses elements of the common syntax, it will
also use the common syntax equivalence rules, namely that the scheme
and hostname are case insensitive and a URL with an explicit ":port",
where the port is the default for the scheme, is equivalent to one
where the port is elided.
7. Security Considerations
A URI does not in itself pose a security threat. Users should beware
that there is no general guarantee that a URL, which at one time
located a given resource, will continue to do so. Nor is there any
guarantee that a URL will not locate a different resource at some
later point in time, due to the lack of any constraint on how a given
authority apportions its namespace. Such a guarantee can only be
obtained from the person(s) controlling that namespace and the
resource in question. A specific URI scheme may include additional
semantics, such as name persistence, if those semantics are required
of all naming authorities for that scheme.
It is sometimes possible to construct a URL such that an attempt to
perform a seemingly harmless, idempotent operation, such as the
retrieval of an entity associated with the resource, will in fact
cause a possibly damaging remote operation to occur. The unsafe URL
is typically constructed by specifying a port number other than that
reserved for the network protocol in question. The client
unwittingly contacts a site that is in fact running a different
protocol. The content of the URL contains instructions that, when
interpreted according to this other protocol, cause an unexpected
operation. An example has been the use of a gopher URL to cause an
unintended or impersonating message to be sent via a SMTP server.
Caution should be used when using any URL that specifies a port
number other than the default for the protocol, especially when it is
a number within the reserved space.
Care should be taken when a URL contains escaped delimiters for a
given protocol (for example, CR and LF characters for telnet
protocols) that these are not unescaped before transmission. This
might violate the protocol, but avoids the potential for such
characters to be used to simulate an extra operation or parameter in
that protocol, which might lead to an unexpected and possibly harmful
remote operation to be performed.
It is clearly unwise to use a URL that contains a password which is
intended to be secret. In particular, the use of a password within
the 'userinfo' component of a URL is strongly disrecommended except
in those rare cases where the 'password' parameter is intended to be
public.
8. Acknowledgements
This document was derived from RFC1738 [RFC1738] and RFC1808
[RFC1808]; the acknowledgements in those specifications still apply.
In addition, contributions by Gisle Aas, Martin Beet, Martin Duerst,
Jim Gettys, Martijn Koster, Dave Kristol, Daniel LaLiberte, Foteos
Macrides, James Marshall, Ryan Moats, Keith Moore, and Lauren Wood
are gratefully acknowledged.
9. References
[RFC2277] Alvestrand, H., "IETF Policy on Character Sets and
Languages", BCP 18, RFC2277, January 1998.
[RFC1630] 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",
RFC1630, June 1994.
[RFC1738] Berners-Lee, T., Masinter, L., and M. McCahill, Editors,
"Uniform Resource Locators (URL)", RFC1738, December 1994.
[RFC1866] Berners-Lee T., and D. Connolly, "HyperText Markup Language
Specification -- 2.0", RFC1866, November 1995.
[RFC1123] Braden, R., Editor, "Requirements for Internet Hosts --
Application and Support", STD 3, RFC1123, October 1989.
[RFC822] Crocker, D., "Standard for the Format of ARPA Internet Text
Messages", STD 11, RFC822, August 1982.
[RFC1808] Fielding, R., "Relative Uniform Resource Locators", RFC
1808, June 1995.
[RFC2046] Freed, N., and N. Borenstein, "Multipurpose Internet Mail
Extensions (MIME) Part Two: Media Types", RFC2046,
November 1996.
[RFC1736] Kunze, J., "Functional Recommendations for Internet
Resource Locators", RFC1736, February 1995.
[RFC2141] Moats, R., "URN Syntax", RFC2141, May 1997.
[RFC1034] Mockapetris, P., "Domain Names - Concepts and Facilities",
STD 13, RFC1034, November 1987.
[RFC2110] Palme, J., and A. Hopmann, "MIME E-mail Encapsulation of
Aggregate Documents, such as HTML (MHTML)", RFC2110, March
1997.
[RFC1737] Sollins, K., and L. Masinter, "Functional Requirements for
Uniform Resource Names", RFC1737, December 1994.
[ASCII] US-ASCII. "Coded Character Set -- 7-bit American Standard
Code for Information Interchange", ANSI X3.4-1986.
[UTF-8] Yergeau, F., "UTF-8, a transformation format of ISO 10646",
RFC2279, January 1998.
10. Authors' Addresses
Tim Berners-Lee
World Wide Web Consortium
MIT Laboratory for Computer Science, NE43-356
545 Technology Square
Cambridge, MA 02139
Fax: +1(617)258-8682
EMail: timbl@w3.org
Roy T. Fielding
Department of Information and Computer Science
University of California, Irvine
Irvine, CA 92697-3425
Fax: +1(949)824-1715
EMail: fielding@ics.uci.edu
Larry Masinter
Xerox PARC
3333 Coyote Hill Road
Palo Alto, CA 94034
Fax: +1(415)812-4333
EMail: masinter@parc.xerox.com
A. Collected BNF for URI
URI-reference = [ absoluteURI | relativeURI ] [ "#" fragment ]
absoluteURI = scheme ":" ( hier_part | opaque_part )
relativeURI = ( net_path | abs_path | rel_path ) [ "?" query ]
hier_part = ( net_path | abs_path ) [ "?" query ]
opaque_part = uric_no_slash *uric
uric_no_slash = unreserved | escaped | ";" | "?" | ":" | "@" |
"&" | "=" | "+" | "$" | ","
net_path = "//" authority [ abs_path ]
abs_path = "/" path_segments
rel_path = rel_segment [ abs_path ]
rel_segment = 1*( unreserved | escaped |
";" | "@" | "&" | "=" | "+" | "$" | "," )
scheme = alpha *( alpha | digit | "+" | "-" | "." )
authority = server | reg_name
reg_name = 1*( unreserved | escaped | "$" | "," |
";" | ":" | "@" | "&" | "=" | "+" )
server = [ [ userinfo "@" ] hostport ]
userinfo = *( unreserved | escaped |
";" | ":" | "&" | "=" | "+" | "$" | "," )
hostport = host [ ":" port ]
host = hostname | IPv4address
hostname = *( domainlabel "." ) toplabel [ "." ]
domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum
toplabel = alpha | alpha *( alphanum | "-" ) alphanum
IPv4address = 1*digit "." 1*digit "." 1*digit "." 1*digit
port = *digit
path = [ abs_path | opaque_part ]
path_segments = segment *( "/" segment )
segment = *pchar *( ";" param )
param = *pchar
pchar = unreserved | escaped |
":" | "@" | "&" | "=" | "+" | "$" | ","
query = *uric
fragment = *uric
uric = reserved | unreserved | escaped
reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
"$" | ","
unreserved = alphanum | mark
mark = "-" | "_" | "." | "!" | "~" | "*" | "'" |
"(" | ")"
escaped = "%" hex hex
hex = digit | "A" | "B" | "C" | "D" | "E" | "F" |
"a" | "b" | "c" | "d" | "e" | "f"
alphanum = alpha | digit
alpha = lowalpha | upalpha
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"
upalpha = "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"
B. Parsing a URI Reference with a Regular Expression
As described in Section 4.3, the generic URI syntax is not sufficient
to disambiguate the components of some forms of URI. Since the
"greedy algorithm" described in that section is identical to the
disambiguation method used by POSIX regular expressions, it is
natural and commonplace to use a regular expression for parsing the
potential four components and fragment identifier of a URI reference.
The following line is the regular expression for breaking-down a URI
reference into its components.
^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
12 3 4 5 6 7 8 9
The numbers in the second line above are only to assist readability;
they indicate the reference points for each subexpression (i.e., each
paired parenthesis). We refer to the value matched for subexpression
<n> as $<n>. For example, matching the above expression to
http://www.ics.uci.edu/pub/ietf/uri/#Related
results in the following subexpression matches:
$1 = http:
$2 = http
$3 = //www.ics.uci.edu
$4 = www.ics.uci.edu
$5 = /pub/ietf/uri/
$6 = <undefined>
$7 = <undefined>
$8 = #Related
$9 = Related
where <undefined> indicates that the component is not present, as is
the case for the query component in the above example. Therefore, we
can determine the value of the four components and fragment as
scheme = $2
authority = $4
path = $5
query = $7
fragment = $9
and, going in the opposite direction, we can recreate a URI reference
from its components using the algorithm in step 7 of Section 5.2.
C. Examples of Resolving Relative URI References
Within an object with a well-defined base URI of
http://a/b/c/d;p?q
the relative URI would be resolved as follows:
C.1. Normal Examples
g:h = g:h
g = http://a/b/c/g
./g = http://a/b/c/g
g/ = http://a/b/c/g/
/g = http://a/g
//g = http://g
?y = http://a/b/c/?y
g?y = http://a/b/c/g?y
#s = (current document)#s
g#s = http://a/b/c/g#s
g?y#s = http://a/b/c/g?y#s
;x = http://a/b/c/;x
g;x = http://a/b/c/g;x
g;x?y#s = http://a/b/c/g;x?y#s
. = http://a/b/c/
./ = http://a/b/c/
.. = http://a/b/
../ = http://a/b/
../g = http://a/b/g
../.. = http://a/
../../ = http://a/
../../g = http://a/g
C.2. Abnormal Examples
Although the following abnormal examples are unlikely to occur in
normal practice, all URI parsers should be capable of resolving them
consistently. Each example uses the same base as above.
An empty reference refers to the start of the current document.
<> = (current document)
Parsers must be careful in handling the case where there are more
relative path ".." segments than there are hierarchical levels in the
base URI's path. Note that the ".." syntax cannot be used to change
the authority component of a URI.
../../../g = http://a/../g
../../../../g = http://a/../../g
In practice, some implementations strip leading relative symbolic
elements (".", "..") after applying a relative URI 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.
Similarly, parsers must avoid treating "." and ".." as special when
they are not complete components of a relative path.
/./g = http://a/./g
/../g = http://a/../g
g. = http://a/b/c/g.
.g = http://a/b/c/.g
g.. = http://a/b/c/g..
..g = http://a/b/c/..g
Less likely are cases where the relative URI uses unnecessary or
nonsensical forms of the "." and ".." complete path segments.
./../g = http://a/b/g
./g/. = http://a/b/c/g/
g/./h = http://a/b/c/g/h
g/../h = http://a/b/c/h
g;x=1/./y = http://a/b/c/g;x=1/y
g;x=1/../y = http://a/b/c/y
All client applications remove the query component from the base URI
before resolving relative URI. 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.
g?y/./x = http://a/b/c/g?y/./x
g?y/../x = http://a/b/c/g?y/../x
g#s/./x = http://a/b/c/g#s/./x
g#s/../x = http://a/b/c/g#s/../x
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.
http:g = http:g ; for validating parsers
| http://a/b/c/g ; for backwards compatibility
D. Embedding the Base URI in HTML documents
It is useful to consider an example of how the base URI 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) [RFC1866] can include an embedded base URI. This appendix
does not form a part of the URI 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 URI for resolving any
relative URI. The "HREF" attribute must be an absolute URI. 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 URI "../x" as representing the absolute URI
<http://www.ics.uci.edu/Test/a/x>
regardless of the context in which the example document was obtained.
E. Recommendations for Delimiting URI in Context
URI are often transmitted through formats that do not provide a clear
context for their interpretation. For example, there are many
occasions when URI are included in plain text; examples include text
sent in electronic mail, USENET news messages, and, most importantly,
printed on paper. In such cases, it is important to be able to
delimit the URI from the rest of the text, and in particular from
punctuation marks that might be mistaken for part of the URI.
In practice, URI are delimited in a variety of ways, but usually
within double-quotes "http://test.com/", angle brackets
<http://test.com/>, or just using whitespace
http://test.com/
These wrappers do not form part of the URI.
In the case where a fragment identifier is associated with a URI
reference, the fragment would be placed within the brackets as well
(separated from the URI with a "#" character).
In some cases, extra whitespace (spaces, linebreaks, tabs, etc.) may
need to be added to break long URI across lines. The whitespace
should be ignored when extracting the URI.
No whitespace should be introduced after a hyphen ("-") character.
Because some typesetters and printers may (erroneously) introduce a
hyphen at the end of line when breaking a line, the interpreter of a
URI containing a line break immediately after a hyphen should ignore
all unescaped whitespace around the line break, and should be aware
that the hyphen may or may not actually be part of the URI.
Using <> angle brackets around each URI is especially recommended as
a delimiting style for URI that contain whitespace.
The prefix "URL:" (with or without a trailing space) was recommended
as a way to used to help distinguish a URL from other bracketed
designators, although this is not common in practice.
For robustness, software that accepts user-typed URI should attempt
to recognize and strip both delimiters and embedded whitespace.
For example, the text:
Yes, Jim, I found it under "http://www.w3.org/Addressing/",
but you can probably pick it up from <ftp://ds.internic.
net/rfc/>. Note the warning in <http://www.ics.uci.edu/pub/
ietf/uri/historical.html#WARNING>.
contains the URI references
http://www.w3.org/Addressing/
ftp://ds.internic.net/rfc/
http://www.ics.uci.edu/pub/ietf/uri/historical.html#WARNING
F. Abbreviated URLs
The URL syntax was designed for unambiguous reference to network
resources and extensibility via the URL scheme. However, as URL
identification and usage have become commonplace, traditional media
(television, radio, newspapers, billboards, etc.) have increasingly
used abbreviated URL references. That is, a reference consisting of
only the authority and path portions of the identified resource, such
as
www.w3.org/Addressing/
or simply the DNS hostname on its own. Such references are primarily
intended for human interpretation rather than machine, with the
assumption that context-based heuristics are sufficient to complete
the URL (e.g., most hostnames beginning with "www" are likely to have
a URL prefix of "http://"). Although there is no standard set of
heuristics for disambiguating abbreviated URL references, many client
implementations allow them to be entered by the user and
heuristically resolved. It should be noted that such heuristics may
change over time, particularly when new URL schemes are introduced.
Since an abbreviated URL has the same syntax as a relative URL path,
abbreviated URL references cannot be used in contexts where relative
URLs are expected. This limits the use of abbreviated URLs to places
where there is no defined base URL, such as dialog boxes and off-line
advertisements.
G. Summary of Non-editorial Changes
G.1. Additions
Section 4 (URI References) was added to stem the confusion regarding
"what is a URI" and how to describe fragment identifiers given that
they are not part of the URI, but are part of the URI syntax and
parsing concerns. In addition, it provides a reference definition
for use by other IETF specifications (HTML, HTTP, etc.) that have
previously attempted to redefine the URI syntax in order to account
for the presence of fragment identifiers in URI references.
Section 2.4 was rewritten to clarify a number of misinterpretations
and to leave room for fully internationalized URI.
Appendix F on abbreviated URLs was added to describe the shortened
references often seen on television and magazine advertisements and
explain why they are not used in other contexts.
G.2. Modifications from both RFC1738 and RFC1808
Changed to URI syntax instead of just URL.
Confusion regarding the terms "character encoding", the URI
"character set", and the escaping of characters with %<hex><hex>
equivalents has (hopefully) been reduced. Many of the BNF rule names
regarding the character sets have been changed to more accurately
describe their purpose and to encompass all "characters" rather than
just US-ASCII octets. Unless otherwise noted here, these
modifications do not affect the URI syntax.
Both RFC1738 and RFC1808 refer to the "reserved" set of characters
as if URI-interpreting software were limited to a single set of
characters with a reserved purpose (i.e., as meaning something other
than the data to which the characters correspond), and that this set
was fixed by the URI scheme. However, this has not been true in
practice; any character that is interpreted differently when it is
escaped is, in effect, reserved. Furthermore, the interpreting
engine on a HTTP server is often dependent on the resource, not just
the URI scheme. The description of reserved characters has been
changed accordingly.
The plus "+", dollar "$", and comma "," characters have been added to
those in the "reserved" set, since they are treated as reserved
within the query component.
The tilde "~" character was added to those in the "unreserved" set,
since it is extensively used on the Internet in spite of the
difficulty to transcribe it with some keyboards.
The syntax for URI scheme has been changed to require that all
schemes begin with an alpha character.
The "user:password" form in the previous BNF was changed to a
"userinfo" token, and the possibility that it might be
"user:password" made scheme specific. In particular, the use of
passwords in the clear is not even suggested by the syntax.
The question-mark "?" character was removed from the set of allowed
characters for the userinfo in the authority component, since testing
showed that many applications treat it as reserved for separating the
query component from the rest of the URI.
The semicolon ";" character was added to those stated as being
reserved within the authority component, since several new schemes
are using it as a separator within userinfo to indicate the type of
user authentication.
RFC1738 specified that the path was separated from the authority
portion of a URI by a slash. RFC1808 followed suit, but with a
fudge of carrying around the separator as a "prefix" in order to
describe the parsing algorithm. RFC1630 never had this problem,
since it considered the slash to be part of the path. In writing
this specification, it was found to be impossible to accurately
describe and retain the difference between the two URI
<foo:/bar> and <foo:bar>
without either considering the slash to be part of the path (as
corresponds to actual practice) or creating a separate component just
to hold that slash. We chose the former.
G.3. Modifications from RFC1738
The definition of specific URL schemes and their scheme-specific
syntax and semantics has been moved to separate documents.
The URL host was defined as a fully-qualified domain name. However,
many URLs are used without fully-qualified domain names (in contexts
for which the full qualification is not necessary), without any host
(as in some file URLs), or with a host of "localhost".
The URL port is now *digit instead of 1*digit, since systems are
expected to handle the case where the ":" separator between host and
port is supplied without a port.
The recommendations for delimiting URI in context (Appendix E) have
been adjusted to reflect current practice.
G.4. Modifications from RFC1808
RFC1808 (Section 4) defined an empty URL reference (a reference
containing nothing aside from the fragment identifier) as being a
reference to the base URL. Unfortunately, that definition could be
interpreted, upon selection of such a reference, as a new retrieval
action on that resource. Since the normal intent of such references
is for the user agent to change its view of the current document to
the beginning of the specified fragment within that document, not to
make an additional request of the resource, a description of how to
correctly interpret an empty reference has been added in Section 4.
The description of the mythical Base header field has been replaced
with a reference to the Content-Location header field defined by
MHTML [RFC2110].
RFC1808 described various schemes as either having or not having the
properties of the generic URI syntax. However, the only requirement
is that the particular document containing the relative references
have a base URI that abides by the generic URI syntax, regardless of
the URI scheme, so the associated description has been updated to
reflect that.
The BNF term <net_loc> has been replaced with <authority>, since the
latter more accurately describes its use and purpose. Likewise, the
authority is no longer restricted to the IP server syntax.
Extensive testing of current client applications demonstrated that
the majority of deployed systems do not use the ";" character to
indicate trailing parameter information, and that the presence of a
semicolon in a path segment does not affect the relative parsing of
that segment. Therefore, parameters have been removed as a separate
component and may now appear in any path segment. Their influence
has been removed from the algorithm for resolving a relative URI
reference. The resolution examples in Appendix C have been modified
to reflect this change.
Implementations are now allowed to work around misformed relative
references that are prefixed by the same scheme as the base URI, but
only for schemes known to use the <hier_part> syntax.
H. Full Copyright Statement
Copyright (C) The Internet Society (1998). All Rights Reserved.
This document and translations of it may be copied and furnished to
others, and derivative works that comment on or otherwise explain it
or assist in its implementation may be prepared, copied, published
and distributed, in whole or in part, without restriction of any
kind, provided that the above copyright notice and this paragraph are
included on all such copies and derivative works. However, this
document itself may not be modified in any way, such as by removing
the copyright notice or references to the Internet Society or other
Internet organizations, except as needed for the purpose of
developing Internet standards in which case the procedures for
copyrights defined in the Internet Standards process must be
followed, or as required to translate it into languages other than
English.
The limited permissions granted above are perpetual and will not be
revoked by the Internet Society or its successors or assigns.
This document and the information contained herein is provided on an
"AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING
TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.