As per Relevance of the word relative, we have this rfc below:
Network Working Group T. Berners-
Request for Comments: 2396 MIT/
Updates: 1808, 1738 R.
Category: Standards Track U.C.
L.
Xerox
August 1998
Uniform Resource Identifiers (URI): Generic
Status of this
This document specifies an Internet standards track protocol for
Internet community, and requests discussion and suggestions
improvements. Please refer to the current edition of the "
Official Protocol Standards" (STD 1) for the standardization
and status of this protocol. Distribution of this memo is unlimited
Copyright
Copyright (C) The Internet Society (1998). All Rights Reserved
IESG
This paper describes a "superset" of operations that can be
to URI. It consists of both a grammar and a description of
functionality for URI. To understand what is a valid URI, both
grammar and the associated description have to be studied. Some
the functionality described is not applicable to all URI schemes,
some operations are only possible when certain media types
retrieved using the URI, regardless of the scheme used
A Uniform Resource Identifier (URI) is a compact string of
for identifying an abstract or physical resource. This
defines the generic syntax of URI, including both absolute
relative forms, and guidelines for their use; it revises and
the generic definitions in RFC 1738 and RFC 1808.
This document defines a grammar that is a superset of all valid URI
such that an implementation can parse the common components of a
reference without knowing the scheme-specific requirements of
possible identifier type. This document does not define a
grammar for URI; that task will be performed by the
specifications of each URI scheme
Berners-Lee, et. al. Standards Track [Page 1]
RFC 2396 URI Generic Syntax August 1998
1.
Uniform Resource Identifiers (URI) provide a simple and
means for identifying a resource. This specification of URI
and semantics is derived from concepts introduced by the World
Web global information initiative, whose use of such objects
from 1990 and is described in "Universal Resource Identifiers in WWW
[RFC1630]. The specification of URI is designed to meet
recommendations laid out in "Functional Recommendations for
Resource Locators" [RFC1736] and "Functional Requirements for
Resource Names" [RFC1737].
This document updates and merges "Uniform Resource Locators
[RFC1738] and "Relative Uniform Resource Locators" [RFC1808] in
to define a single, generic syntax for all URI. It excludes
portions of RFC 1738 that defined the specific syntax of
URL schemes; those portions will be updated as separate documents,
will the process for registration of new URI schemes. This
does not discuss the issues and recommendation for dealing
characters outside of the US-ASCII character set [ASCII];
recommendations are discussed in a separate document
All significant changes from the prior RFCs are noted in Appendix G
1.1 Overview of
URI are characterized by the following definitions
Uniformity provides several benefits: it allows different
of resource identifiers to be used in the same context,
when the mechanisms used to access those resources may differ
it allows uniform semantic interpretation of common
conventions across different types of resource identifiers;
allows introduction of new types of resource
without interfering with the way that existing identifiers
used; and, it allows the identifiers to be reused in
different contexts, thus permitting new applications
protocols to leverage a pre-existing, large, and widely-
set of resource identifiers
A resource can be anything that has identity.
examples include an electronic document, an image, a
(e.g., "today's weather report for Los Angeles"), and
collection of other resources. Not all resources are
"retrievable"; e.g., human beings, corporations, and
books in a library can also be considered resources
Berners-Lee, et. al. Standards Track [Page 2]
RFC 2396 URI Generic Syntax August 1998
The resource is the conceptual mapping to an entity or set
entities, not necessarily the entity which corresponds to
mapping at any particular instance in time. Thus, a
can remain constant even when its content---the entities
which it currently corresponds---changes over time,
that the conceptual mapping is not changed in the process
An identifier is an object that can act as a reference
something that has identity. In the case of URI, the object
a sequence of characters with a restricted syntax
Having identified a resource, a system may perform a variety
operations on the resource, as might be characterized by such
as `access', `update', `replace', or `find attributes'.
1.2. URI, URL, and
A URI can be further classified as a locator, a name, or both.
term "Uniform Resource Locator" (URL) refers to the subset of
that identify resources via a representation of their primary
mechanism (e.g., their network "location"), rather than
the resource by name or by some other attribute(s) of that resource
The term "Uniform Resource Name" (URN) refers to the subset of
that are required to remain globally unique and persistent even
the resource ceases to exist or becomes unavailable
The URI scheme (Section 3.1) defines the namespace of the URI,
thus may further restrict the syntax and semantics of
using that scheme. This specification defines those elements of
URI syntax that are either required of all URI schemes or are
to many URI schemes. It thus defines the syntax and semantics
are needed to implement a scheme-independent parsing mechanism
URI references, such that the scheme-dependent handling of a URI
be postponed until the scheme-dependent semantics are needed. We
the term URL below when describing syntax or semantics that
apply to locators
Although many URL schemes are named after protocols, this does
imply that the only way to access the URL's resource is via the
protocol. Gateways, proxies, caches, and name resolution
might be used to access some resources, independent of the
of their origin, and the resolution of some URL may require the
of more than one protocol (e.g., both DNS and HTTP are typically
to access an "http" URL's resource when it can't be found in a
cache).
Berners-Lee, et. al. Standards Track [Page 3]
RFC 2396 URI Generic Syntax August 1998
A URN differs from a URL in that it's primary purpose is
labeling of a resource with an identifier. That identifier is
from one of a set of defined namespaces, each of which has its
set name structure and assignment procedures. The "urn" scheme
been reserved to establish the requirements for a standardized
namespace, as defined in "URN Syntax" [RFC2141] and its
specifications
Most of the examples in this specification demonstrate URL,
they allow the most varied use of the syntax and often have
hierarchical namespace. A parser of the URI syntax is capable
parsing both URL and URN references as a generic URI; once the
is determined, the scheme-specific parsing can be performed on
generic URI components. In other words, the URI syntax is a
of the syntax of all URI schemes
1.3. Example
The following examples illustrate URI that are in common use
ftp://ftp.is.co.za/rfc/rfc1808.
-- ftp scheme for File Transfer Protocol
gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20
-- gopher scheme for Gopher and Gopher+ Protocol
http://www.math.uio.no/faq/compression-faq/part1.
-- http scheme for Hypertext Transfer Protocol
mailto:mduerst@ifi.unizh.
-- mailto scheme for electronic mail
news:comp.infosystems.www.servers.
-- news scheme for USENET news groups and
telnet://melvyl.ucop.edu
-- telnet scheme for interactive services via the TELNET
1.4. Hierarchical URI and Relative
An absolute identifier refers to a resource independent of
context in which the identifier is used. In contrast, a
identifier refers to a resource by describing the difference within
hierarchical namespace between the current context and an
identifier of the resource
Berners-Lee, et. al. Standards Track [Page 4]
RFC 2396 URI Generic Syntax August 1998
Some URI schemes support a hierarchical naming system, where
hierarchy of the name is denoted by a "/" delimiter separating
components in the scheme. This document defines a scheme-
`relative' form of URI reference that can be used in conjunction
a `base' URI (of a hierarchical scheme) to produce another URI.
syntax of hierarchical URI is described in Section 3; the
URI calculation is described in Section 5.
1.5. URI
The URI syntax was designed with global transcribability as one
its main concerns. A URI is a sequence of characters from a
limited set, i.e. the letters of the basic Latin alphabet, digits
and a few special characters. A URI may be represented in a
of ways: e.g., ink on paper, pixels on a screen, or a sequence
octets in a coded character set. The interpretation of a URI
only on the characters used and not how those characters
represented in a network protocol
The goal of transcribability can be described by a simple scenario
Imagine two colleagues, Sam and Kim, sitting in a pub at
international conference and exchanging research ideas. Sam asks
for a location to get more information, so Kim writes the URI for
research site on a napkin. Upon returning home, Sam takes out
napkin and types the URI into a computer, which then retrieves
information to which Kim referred
There are several design concerns revealed by the scenario
o A URI is a sequence of characters, which is not
represented as a sequence of octets
o A URI may be transcribed from a non-network source, and
should consist of characters that are most likely to be able
be typed into a computer, within the constraints imposed
keyboards (and related input devices) across languages
locales
o A URI often needs to be remembered by people, and it is
for people to remember a URI when it consists of
components
These design concerns are not always in alignment. For example,
is often the case that the most meaningful name for a URI
would require characters that cannot be typed into some systems.
ability to transcribe the resource identifier from one medium
another was considered more important than having its URI consist
the most meaningful of components. In local and regional
Berners-Lee, et. al. Standards Track [Page 5]
RFC 2396 URI Generic Syntax August 1998
and with improving technology, users might benefit from being able
use a wider range of characters; such use is not defined in
document
1.6. Syntax Notation and Common
This document uses two conventions to describe and define the
for URI. The first, called the layout form, is a general
of the order of components and component separators, as
/;?
The component names are enclosed in angle-brackets and any
outside angle-brackets are literal separators. Whitespace should
ignored. These descriptions are used informally and do not
the syntax requirements
The second convention is a BNF-like grammar, used to define
formal URI syntax. The grammar is that of [RFC822], except that "|"
is used to designate alternatives. Briefly, rules are separated
definitions by an equal "=", indentation is used to continue a
definition over more than one line, literals are quoted with "",
parentheses "(" and ")" are used to group elements, optional
are enclosed in "[" and "]" brackets, and elements may be
with * to designate n or more repetitions of the
element; n defaults to 0.
Unlike many specifications that use a BNF-like grammar to define
bytes (octets) allowed by a protocol, the URI grammar is defined
terms of characters. Each literal in the grammar corresponds to
character it represents, rather than to the octet encoding of
character in any particular coded character set. How a URI
represented in terms of bits and bytes on the wire is dependent
the character encoding of the protocol used to transport it, or
charset of the document which contains it
The following definitions are common to many elements
alpha = lowalpha |
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
Berners-Lee, et. al. Standards Track [Page 6]
RFC 2396 URI Generic Syntax August 1998
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" |
"8" | "9"
alphanum = alpha |
The complete URI syntax is collected in Appendix A
2. URI Characters and Escape
URI consist of a restricted set of characters, primarily chosen
aid transcribability and usability both in computer systems and
non-computer communications. Characters used conventionally
delimiters around URI were excluded. The restricted set
characters consists of digits, letters, and a few graphic
were chosen from those common to most of the character encodings
input facilities available to Internet users
uric = reserved | unreserved |
Within a URI, characters are either used as delimiters, or
represent strings of data (octets) within the delimited portions
Octets are either represented directly by a character (using the US
ASCII character for that octet [ASCII]) or by an escape encoding
This representation is elaborated below
2.1 URI and non-ASCII
The relationship between URI and characters has been a source
confusion for characters that are not part of US-ASCII. To
the relationship, it is useful to distinguish between a "character
(as a distinguishable semantic entity) and an "octet" (an 8-
byte). There are two mappings, one from URI characters to octets,
a second from octets to original characters
URI character sequence->octet sequence->original character
A URI is represented as a sequence of characters, not as a
of octets. That is because URI might be "transported" by means
are not through a computer network, e.g., printed on paper, read
the radio, etc
A URI scheme may define a mapping from URI characters to octets
whether this is done depends on the scheme. Commonly, within
delimited component of a URI, a sequence of characters may be used
represent a sequence of octets. For example, the character "a
represents the octet 97 (decimal), while the character sequence "%",
"0", "a" represents the octet 10 (decimal).
Berners-Lee, et. al. Standards Track [Page 7]
RFC 2396 URI Generic Syntax August 1998
There is a second translation for some resources: the sequence
octets defined by a component of the URI is subsequently used
represent a sequence of characters. A 'charset' defines this mapping
There are many charsets in use in Internet protocols. For example
UTF-8 [UTF-8] defines a mapping from sequences of octets to
of characters in the repertoire of ISO 10646.
In the simplest case, the original character sequence contains
characters that are defined in US-ASCII, and the two levels
mapping are simple and easily invertible: each 'original character
is represented as the octet for the US-ASCII code for it, which is
in turn, represented as either the US-ASCII character, or else
"%" escape sequence for that octet
For original character sequences that contain non-ASCII characters
however, the situation is more difficult. Internet protocols
transmit octet sequences intended to represent character
are expected to provide some way of identifying the charset used,
there might be more than one [RFC2277]. However, there is
no provision within the generic URI syntax to accomplish
identification. An individual URI scheme may require a
charset, define a default charset, or provide a way to indicate
charset used
It is expected that a systematic treatment of character
within URI will be developed as a future modification of
specification
2.2. Reserved
Many URI include components consisting of or delimited by,
special characters. These characters are called "reserved",
their usage within the URI component is limited to their
purpose. If the data for a URI component would conflict with
reserved purpose, then the conflicting data must be escaped
forming the URI
reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
"$" | ","
The "reserved" syntax class above refers to those characters that
allowed within a URI, but which may not be allowed within
particular component of the generic URI syntax; they are used
delimiters of the components described in Section 3.
Berners-Lee, et. al. Standards Track [Page 8]
RFC 2396 URI Generic Syntax August 1998
Characters in the "reserved" set are not reserved in all contexts
The set of characters actually reserved within any given
component is defined by that component. In general, a character
reserved if the semantics of the URI changes if the character
replaced with its escaped US-ASCII encoding
2.3. Unreserved
Data characters that are allowed in a URI but do not have a
purpose are called unreserved. These include upper and lower
letters, decimal digits, and a limited set of punctuation marks
symbols
unreserved = alphanum |
mark = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")"
Unreserved characters can be escaped without changing the
of the URI, but this should not be done unless the URI is being
in a context that does not allow the unescaped character to appear
2.4. Escape
Data must be escaped if it does not have a representation using
unreserved character; this includes data that does not correspond
a printable character of the US-ASCII coded character set, or
corresponds to any US-ASCII character that is disallowed,
explained below
2.4.1. Escaped
An escaped octet is encoded as a character triplet, consisting of
percent character "%" followed by the two hexadecimal
representing the octet code. For example, "%20" is the
encoding for the US-ASCII space character
escaped = "%" hex
hex = digit | "A" | "B" | "C" | "D" | "E" | "F" |
"a" | "b" | "c" | "d" | "e" | "f
2.4.2. When to Escape and
A URI is always in an "escaped" form, since escaping or unescaping
completed URI might change its semantics. Normally, the only
escape encodings can safely be made is when the URI is being
from its component parts; each component may have its own set
characters that are reserved, so only the mechanism responsible
generating or interpreting that component can determine whether
Berners-Lee, et. al. Standards Track [Page 9]
RFC 2396 URI Generic Syntax August 1998
not escaping a character will change its semantics. Likewise, a
must be separated into its components before the escaped
within those components can be safely decoded
In some cases, data that could be represented by an
character may appear escaped; for example, some of the
"mark" characters are automatically escaped by some systems. If
given URI scheme defines a canonicalization algorithm,
unreserved characters may be unescaped according to that algorithm
For example, "%7e" is sometimes used instead of "~" in an http
path, but the two are equivalent for an http URL
Because the percent "%" character always has the reserved purpose
being the escape indicator, it must be escaped as "%25" in order
be used as data within a URI. Implementers should be careful not
escape or unescape the same string more than once, since
an already unescaped string might lead to misinterpreting a
data character as another escaped character, or vice versa in
case of escaping an already escaped string
2.4.3. Excluded US-ASCII
Although they are disallowed within the URI syntax, we include here
description of those US-ASCII characters that have been excluded
the reasons for their exclusion
The control characters in the US-ASCII coded character set are
used within a URI, both because they are non-printable and
they are likely to be misinterpreted by some control mechanisms
control = hexadecimal
The space character is excluded because significant spaces
disappear and insignificant spaces may be introduced when URI
transcribed or typeset or subjected to the treatment of word
processing programs. Whitespace is also used to delimit URI in
contexts
space = character 20 hexadecimal
The angle-bracket "<" and ">" and double-quote (") characters
excluded because they are often used as the delimiters around URI
text documents and protocol fields. The character "#" is
because it is used to delimit a URI from a fragment identifier in
references (Section 4). The percent character "%" is excluded
it is used for the encoding of escaped characters
delims = "<" | ">" | "#" | "%" | <">
Berners-Lee, et. al. Standards Track [Page 10]
RFC 2396 URI Generic Syntax August 1998
Other characters are excluded because gateways and other
agents are known to sometimes modify such characters, or they
used as delimiters
unwise = "{" | "}" | "|" | "\" | "^" | "[" | "]" | "`"
Data corresponding to excluded characters must be escaped in order
be properly represented within a URI
3. URI Syntactic
The URI syntax is dependent upon the scheme. In general,
URI are written as follows
:specific-part
An absolute URI contains the name of the scheme being used ()
followed by a colon (":") and then a string (the specific
part>) whose interpretation depends on the scheme
The URI syntax does not require that the scheme-specific-part
any general structure or set of semantics which is common among
URI. However, a subset of URI do share a common syntax
representing hierarchical relationships within the namespace.
"generic URI" syntax consists of a sequence of four main components
://<authority>?
each of which, except , may be absent from a particular URI
For example, some URI schemes do not allow an <authority> component
and others do not use a component
absoluteURI = scheme ":" ( hier_part | opaque_part )
URI that are hierarchical in nature use the slash "/" character
separating hierarchical components. For some file systems, a "/"
character (used to denote the hierarchical structure of a URI) is
delimiter used to construct a file name hierarchy, and thus the
path will look similar to a file pathname. This does NOT imply
the resource is a file or that the URI maps to an actual
pathname
hier_part = ( net_path | abs_path ) [ "?" query ]
net_path = "//" authority [ abs_path ]
abs_path = "/" path_
Berners-Lee, et. al. Standards Track [Page 11]
RFC 2396 URI Generic Syntax August 1998
URI that do not make use of the slash "/" character for
hierarchical components are considered opaque by the generic
parser
opaque_part = uric_no_slash *
uric_no_slash = unreserved | escaped | ";" | "?" | ":" | "@" |
"&" | "=" | "+" | "$" | ","
We use the term to refer to both the
constructs, since they are mutually exclusive for
given URI and can be parsed as a single component
3.1. Scheme
Just as there are many different methods of access to resources
there are a variety of schemes for identifying such resources.
URI syntax consists of a sequence of components separated by
characters, with the first component defining the semantics for
remainder of the URI string
Scheme names consist of a sequence of characters beginning with
lower case letter and followed by any combination of lower
letters, digits, plus ("+"), period ("."), or hyphen ("-").
resiliency, programs interpreting URI should treat upper case
as equivalent to lower case in scheme names (e.g., allow "HTTP"
well as "http").
scheme = alpha *( alpha | digit | "+" | "-" | "." )
Relative URI references are distinguished from absolute URI in
they do not begin with a scheme name. Instead, the scheme
inherited from the base URI, as described in Section 5.2.
3.2. Authority
Many URI schemes include a top hierarchical element for a
authority, such that the namespace defined by the remainder of
URI is governed by that authority. This authority component
typically defined by an Internet-based server or a scheme-
registry of naming authorities
authority = server | reg_
The authority component is preceded by a double slash "//" and
terminated by the next slash "/", question-mark "?", or by the end
the URI. Within the authority component, the characters ";", ":",
"@", "?", and "/" are reserved
Berners-Lee, et. al. Standards Track [Page 12]
RFC 2396 URI Generic Syntax August 1998
An authority component is not required for a URI scheme to make
of relative references. A base URI without an authority
implies that any relative reference will also be without an
component
3.2.1. Registry-based Naming
The structure of a registry-based naming authority is specific to
URI scheme, but constrained to the allowed characters for
authority component
reg_name = 1*( unreserved | escaped | "$" | "," |
";" | ":" | "@" | "&" | "=" | "+" )
3.2.2. Server-based Naming
URL schemes that involve the direct use of an IP-based protocol to
specified server on the Internet use a common syntax for the
component of the URI's scheme-specific data
@:
where may consist of a user name and, optionally, scheme
specific information about how to gain authorization to access
server. The parts "@" and ":" may be omitted
server = [ [ userinfo "@" ] hostport ]
The user information, if present, is followed by a commercial at-
"@".
userinfo = *( unreserved | escaped |
";" | ":" | "&" | "=" | "+" | "$" | "," )
Some URL schemes use the format "user:password" in the
field. This practice is NOT RECOMMENDED, because the passing
authentication information in clear text (such as URI) has proven
be a security risk in almost every case where it has been used
The host is a domain name of a network host, or its IPv4 address as
set of four decimal digit groups separated by ".". Literal IPv
addresses are not supported
hostport = host [ ":" port ]
host = hostname | IPv4
hostname = *( domainlabel "." ) toplabel [ "." ]
domainlabel = alphanum | alphanum *( alphanum | "-" )
toplabel = alpha | alpha *( alphanum | "-" )
Berners-Lee, et. al. Standards Track [Page 13]
RFC 2396 URI Generic Syntax August 1998
IPv4address = 1*digit "." 1*digit "." 1*digit "." 1*
port = *
Hostnames take the form described in Section 3 of [RFC1034]
Section 2.1 of [RFC1123]: a sequence of domain labels separated
".", each domain label starting and ending with an
character and possibly also containing "-" characters. The
domain label of a fully qualified domain name will never start with
digit, thus syntactically distinguishing domain names from IPv
addresses, and may be followed by a single "." if it is necessary
distinguish between the complete domain name and any local domain
To actually be "Uniform" as a resource locator, a URL hostname
be a fully qualified domain name. In practice, however, the
component may be a local domain literal
Note: A suitable representation for including a literal IPv
address as the host part of a URL is desired, but has not yet
determined or implemented in practice
The port is the network port number for the server. Most
designate protocols that have a default port number. Another
number may optionally be supplied, in decimal, separated from
host by a colon. If the port is omitted, the default port number
assumed
3.3. Path
The path component contains data, specific to the authority (or
scheme if there is no authority component), identifying the
within the scope of that scheme and authority
path = [ abs_path | opaque_part ]
path_segments = segment *( "/" segment )
segment = *pchar *( ";" param )
param = *
pchar = unreserved | escaped |
":" | "@" | "&" | "=" | "+" | "$" | ","
The path may consist of a sequence of path segments separated by
single slash "/" character. Within a path segment, the
"/", ";", "=", and "?" are reserved. Each path segment may include
sequence of parameters, indicated by the semicolon ";" character
The parameters are not significant to the parsing of
references
Berners-Lee, et. al. Standards Track [Page 14]
RFC 2396 URI Generic Syntax August 1998
3.4. Query
The query component is a string of information to be interpreted
the resource
query = *
Within a query component, the characters ";", "/", "?", ":", "@",
"&", "=", "+", ",", and "$" are reserved
4. URI
The term "URI-reference" is used here to denote the common usage of
resource identifier. A URI reference may be absolute or relative
and may have additional information attached in the form of
fragment identifier. However, "the URI" that results from such
reference includes only the absolute URI after the
identifier (if any) is removed and after any relative URI is
to its absolute form. Although it is possible to limit
discussion of URI syntax and semantics to that of the
result, most usage of URI is within general URI references, and it
impossible to obtain the URI from such a reference without
parsing the fragment and resolving the relative form
URI-reference = [ absoluteURI | relativeURI ] [ "#" fragment ]
The syntax for relative URI is a shortened form of that for
URI, where some prefix of the URI is missing and certain
components ("." and "..") have a special meaning when, and only when
interpreting a relative path. The relative URI syntax is defined
Section 5.
4.1. Fragment
When a URI reference is used to perform a retrieval action on
identified resource, the optional fragment identifier, separated
the URI by a crosshatch ("#") character, consists of
reference information to be interpreted by the user agent after
retrieval action has been successfully completed. As such, it is
part of a URI, but is often used in conjunction with a URI
fragment = *
The semantics of a fragment identifier is a property of the
resulting from a retrieval action, regardless of the type of URI
in the reference. Therefore, the format and interpretation
fragment identifiers is dependent on the media type [RFC2046] of
retrieval result. The character restrictions described in Section 2
Berners-Lee, et. al. Standards Track [Page 15]
RFC 2396 URI Generic Syntax August 1998
for URI also apply to the fragment in a URI-reference.
media types may define additional restrictions or structure
the fragment for specifying different types of "partial views"
can be identified within that media type
A fragment identifier is only meaningful when a URI reference
intended for retrieval and the result of that retrieval is a
for which the identified fragment is consistently defined
4.2. Same-document
A URI reference that does not contain a URI is a reference to
current document. In other words, an empty URI reference within
document is interpreted as a reference to the start of that document
and a reference containing only a fragment identifier is a
to the identified fragment of that document. Traversal of such
reference should not result in an additional retrieval action
However, if the URI reference occurs in a context that is
intended to result in a new request, as in the case of HTML's
element, then an empty URI reference represents the base URI of
current document and should be replaced by that URI when
into a request
4.3. Parsing a URI
A URI reference is typically parsed according to the four
components and fragment identifier in order to determine
components are present and whether the reference is relative
absolute. The individual components are then parsed for
subparts and, if not opaque, to verify their validity
Although the BNF defines what is allowed in each component, it
ambiguous in terms of differentiating between an authority
and a path component that begins with two slash characters.
greedy algorithm is used for disambiguation: the left-most
rule soaks up as much of the URI reference string as it is capable
matching. In other words, the authority component wins
Readers familiar with regular expressions should see Appendix B for
concrete parsing example and test oracle
5. Relative URI
It is often the case that a group or "tree" of documents has
constructed to serve a common purpose; the vast majority of URI
these documents point to resources within the tree rather
Berners-Lee, et. al. Standards Track [Page 16]
RFC 2396 URI Generic Syntax August 1998
outside of it. Similarly, documents located at a particular site
much more likely to refer to other resources at that site than
resources at remote sites
Relative addressing of URI allows document trees to be
independent of their location and access scheme. For instance, it
possible for a single set of hypertext documents to be
accessible and traversable via each of the "file", "http", and "ftp
schemes if the documents refer to each other using relative URI
Furthermore, such document trees can be moved, as a whole,
changing any of the relative references. Experience within the
has demonstrated that the ability to perform relative referencing
necessary for the long-term usability of embedded URI
The syntax for relative URI takes advantage of the
of (Section 3) in order to express a reference that
relative to the namespace of another hierarchical URI
relativeURI = ( net_path | abs_path | rel_path ) [ "?" query ]
A relative reference beginning with two slash characters is termed
network-path reference, as defined by in Section 3.
references are rarely used
A relative reference beginning with a single slash character
termed an absolute-path reference, as defined by
Section 3.
A relative reference that does not begin with a scheme name or
slash character is termed a relative-path reference
rel_path = rel_segment [ abs_path ]
rel_segment = 1*( unreserved | escaped |
";" | "@" | "&" | "=" | "+" | "$" | "," )
Within a relative-path reference, the complete path segments "."
".." have special meanings: "the current hierarchy level" and "
level above this hierarchy level", respectively. Although this
very similar to their use within Unix-based filesystems to
directory levels, these path components are only considered
when resolving a relative-path reference to its absolute
(Section 5.2).
Authors should be aware that a path segment which contains a
character cannot be used as the first segment of a relative URI
(e.g., "this:that"), because it would be mistaken for a scheme name
Berners-Lee, et. al. Standards Track [Page 17]
RFC 2396 URI Generic Syntax August 1998
It is therefore necessary to precede such segments with
segments (e.g., "./this:that") in order for them to be referenced
a relative path
It is not necessary for all URI within a given scheme to
restricted to the syntax, since the
properties of that syntax are only necessary when relative URI
used within a particular document. Documents can only make use
relative URI when their base URI fits within the syntax
It is assumed that any document which contains a relative
will also have a base URI that obeys the syntax. In other words
relative URI cannot be used within a document that has an
base URI
Some URI schemes do not allow a hierarchical syntax matching
syntax, and thus cannot use relative references
5.1. Establishing a Base
The term "relative URI" implies that there exists some absolute "
URI" against which the relative reference is applied. Indeed,
base URI is necessary to define the semantics of any relative
reference; without it, a relative reference is meaningless. In
for relative URI to be usable within a document, the base URI of
document must be known to the parser
The base URI of a document can be established in one of four ways
listed below in order of precedence. The order of precedence can
thought of in terms of layers, where the innermost defined base
has the highest precedence. This can be visualized graphically as
.----------------------------------------------------------.
| .----------------------------------------------------. |
| | .----------------------------------------------. | |
| | | .----------------------------------------. | | |
| | | | .----------------------------------. | | | |
| | | | | <relative_reference> | | | | |
| | | | `----------------------------------' | | | |
| | | | (5.1.1) Base URI embedded in the | | | |
| | | | document's content | | | |
| | | `----------------------------------------' | | |
| | | (5.1.2) Base URI of the encapsulating entity | | |
| | | (message, document, or none). | | |
| | `----------------------------------------------' | |
| | (5.1.3) URI used to retrieve the entity | |
| `----------------------------------------------------' |
| (5.1.4) Default Base URI is application-dependent |
`----------------------------------------------------------'
Berners-Lee, et. al. Standards Track [Page 18]
RFC 2396 URI Generic Syntax August 1998
5.1.1. Base URI within Document
Within certain document media types, the base URI of the document
be embedded within the content itself such that it can be
obtained by a parser. This can be useful for descriptive documents
such as tables of content, which may be transmitted to others
protocols other than their usual retrieval context (e.g., E-Mail
USENET news).
It is beyond the scope of this document to specify how, for
media type, the base URI can be embedded. It is assumed that
agents manipulating such media types will be able to obtain
appropriate syntax from that media type's specification. An
of how the base URI can be embedded in the Hypertext Markup
(HTML) [RFC1866] is provided in Appendix D
A mechanism for embedding the base URI within MIME container
(e.g., the message and multipart types) is defined by
[RFC2110]. Protocols that do not use the MIME message header syntax
but which do allow some form of tagged metainformation to be
within messages, may define their own syntax for defining the
URI as part of a message
5.1.2. Base URI from the Encapsulating
If no base URI is embedded, the base URI of a document is defined
the document's retrieval context. For a document that is
within another entity (such as a message or another document),
retrieval context is that entity; thus, the default base URI of
document is the base URI of the entity in which the document
encapsulated
5.1.3. Base URI from the Retrieval
If no base URI is embedded and the document is not
within some other entity (e.g., the top level of a composite entity),
then, if a URI was used to retrieve the base document, that URI
be considered the base URI. Note that if the retrieval was
result of a redirected request, the last URI used (i.e., that
resulted in the actual retrieval of the document) is the base URI
5.1.4. Default Base
If none of the conditions described in Sections 5.1.1--5.1.3 apply
then the base URI is defined by the context of the application
Since this definition is necessarily application-dependent,
Berners-Lee, et. al. Standards Track [Page 19]
RFC 2396 URI Generic Syntax August 1998
to define the base URI using one of the other methods may result
the same content being interpreted differently by different types
application
It is the responsibility of the distributor(s) of a
containing relative URI to ensure that the base URI for that
can be established. It must be emphasized that relative URI
be used reliably in situations where the document's base URI is
well-defined
5.2. Resolving Relative References to Absolute
This section describes an example algorithm for resolving
references that might be relative to a given base URI
The base URI is established according to the rules of Section 5.1
parsed into the four main components as described in Section 3.
that only the scheme component is required to be present in the
URI; the other components may be empty or undefined. A component
undefined if its preceding separator does not appear in the
reference; the path component is never undefined, though it may
empty. The base URI's query component is not used by the
algorithm and may be discarded
For each URI reference, the following steps are performed in order
1) The URI reference is parsed into the potential four components
fragment identifier, as described in Section 4.3.
2) If the path component is empty and the scheme, authority,
query components are undefined, then it is a reference to
current document and we are done. Otherwise, the reference URI'
query and fragment components are defined as found (or not found
within the URI reference and not inherited from the base URI
3) If the scheme component is defined, indicating that the
starts with a scheme name, then the reference is interpreted as
absolute URI and we are done. Otherwise, the reference URI'
scheme is inherited from the base URI's scheme component
Due to a loophole in prior specifications [RFC1630], some
allow the scheme name to be present in a relative URI if it is
same as the base URI scheme. Unfortunately, this can
with the correct parsing of non-hierarchical URI. For
compatibility, an implementation may work around such
by removing the scheme if it matches that of the base URI and
scheme is known to always use the syntax. The
Berners-Lee, et. al. Standards Track [Page 20]
RFC 2396 URI Generic Syntax August 1998
can then continue with the steps below for the remainder of
reference components. Validating parsers should mark such
misformed relative reference as an error
4) If the authority component is defined, then the reference is
network-path and we skip to step 7. Otherwise, the
URI's authority is inherited from the base URI's
component, which will also be undefined if the URI scheme does
use an authority component
5) If the path component begins with a slash character ("/"),
the reference is an absolute-path and we skip to step 7.
6) If this step is reached, then we are resolving a relative-
reference. The relative path needs to be merged with the
URI's path. Although there are many ways to do this, we
describe a simple method using a separate string buffer
a) All but the last segment of the base URI's path component
copied to the buffer. In other words, any characters after
last (right-most) slash character, if any, are excluded
b) The reference's path component is appended to the
string
c) All occurrences of "./", where "." is a complete path segment
are removed from the buffer string
d) If the buffer string ends with "." as a complete path segment
that "." is removed
e) All occurrences of "/../", where is
complete path segment not equal to "..", are removed from
buffer string. Removal of these path segments is
iteratively, removing the leftmost matching pattern on
iteration, until no matching pattern remains
f) If the buffer string ends with "/..", where
is a complete path segment not equal to "..",
"/.." is removed
g) If the resulting buffer string still begins with one or
complete path segments of "..", then the reference
considered to be in error. Implementations may handle
error by retaining these components in the resolved path (i.e.,
treating them as part of the final URI), by removing them
the resolved path (i.e., discarding relative levels above
root), or by avoiding traversal of the reference
Berners-Lee, et. al. Standards Track [Page 21]
RFC 2396 URI Generic Syntax August 1998
h) The remaining buffer string is the reference URI's new
component
7) The resulting URI components, including any inherited from
base URI, are recombined to give the absolute form of the
reference. Using pseudocode, this would
result = ""
if scheme is defined
append scheme to
append ":" to
if authority is defined
append "//" to
append authority to
append path to
if query is defined
append "?" to
append query to
if fragment is defined
append "#" to
append fragment to
return
Note that we must be careful to preserve the distinction between
component that is undefined, meaning that its separator was
present in the reference, and a component that is empty,
that the separator was present and was immediately followed by
next component separator or the end of the reference
The above algorithm is intended to provide an example by which
output of implementations can be tested -- implementation of
algorithm itself is not required. For example, some systems may
it more efficient to implement step 6 as a pair of segment
being merged, rather than as a series of string pattern replacements
Note: Some WWW client applications will fail to separate
reference's query component from its path component before
the base and reference paths in step 6 above. This may result
a loss of information if the query component contains the
"/../" or "/./".
Resolution examples are provided in Appendix C
Berners-Lee, et. al. Standards Track [Page 22]
RFC 2396 URI Generic Syntax August 1998
6. URI Normalization and
In many cases, different URI strings may actually identify
identical resource. For example, the host names used in URL
actually case insensitive, and the URL
equivalent to . In general, the rules
equivalence and definition of a normal form, if any, are
dependent. When a scheme uses elements of the common syntax, it
also use the common syntax equivalence rules, namely that the
and hostname are case insensitive and a URL with an explicit ":port",
where the port is the default for the scheme, is equivalent to
where the port is elided
7. Security
A URI does not in itself pose a security threat. Users should
that there is no general guarantee that a URL, which at one
located a given resource, will continue to do so. Nor is there
guarantee that a URL will not locate a different resource at
later point in time, due to the lack of any constraint on how a
authority apportions its namespace. Such a guarantee can only
obtained from the person(s) controlling that namespace and
resource in question. A specific URI scheme may include
semantics, such as name persistence, if those semantics are
of all naming authorities for that scheme
It is sometimes possible to construct a URL such that an attempt
perform a seemingly harmless, idempotent operation, such as
retrieval of an entity associated with the resource, will in
cause a possibly damaging remote operation to occur. The unsafe
is typically constructed by specifying a port number other than
reserved for the network protocol in question. The
unwittingly contacts a site that is in fact running a
protocol. The content of the URL contains instructions that,
interpreted according to this other protocol, cause an
operation. An example has been the use of a gopher URL to cause
unintended or impersonating message to be sent via a SMTP server
Caution should be used when using any URL that specifies a
number other than the default for the protocol, especially when it
a number within the reserved space
Care should be taken when a URL contains escaped delimiters for
given protocol (for example, CR and LF characters for
protocols) that these are not unescaped before transmission.
might violate the protocol, but avoids the potential for
Berners-Lee, et. al. Standards Track [Page 23]
RFC 2396 URI Generic Syntax August 1998
characters to be used to simulate an extra operation or parameter
that protocol, which might lead to an unexpected and possibly
remote operation to be performed
It is clearly unwise to use a URL that contains a password which
intended to be secret. In particular, the use of a password
the 'userinfo' component of a URL is strongly disrecommended
in those rare cases where the 'password' parameter is intended to
public
8.
This document was derived from RFC 1738 [RFC1738] and RFC 1808
[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,
Macrides, James Marshall, Ryan Moats, Keith Moore, and Lauren
are gratefully acknowledged
9.
[RFC2277] Alvestrand, H., "IETF Policy on Character Sets
Languages", BCP 18, RFC 2277, January 1998.
[RFC1630] Berners-Lee, T., "Universal Resource Identifiers in WWW:
Unifying Syntax for the Expression of Names and
of Objects on the Network as used in the World-Wide Web",
RFC 1630, June 1994.
[RFC1738] Berners-Lee, T., Masinter, L., and M. McCahill, Editors
"Uniform Resource Locators (URL)", RFC 1738, December 1994.
[RFC1866] Berners-Lee T., and D. Connolly, "HyperText Markup
Specification -- 2.0", RFC 1866, November 1995.
[RFC1123] Braden, R., Editor, "Requirements for Internet Hosts --
Application and Support", STD 3, RFC 1123, October 1989.
[RFC822] Crocker, D., "Standard for the Format of ARPA Internet
Messages", STD 11, RFC 822, August 1982.
[RFC1808] Fielding, R., "Relative Uniform Resource Locators",
1808, June 1995.
[RFC2046] Freed, N., and N. Borenstein, "Multipurpose Internet
Extensions (MIME) Part Two: Media Types", RFC 2046,
November 1996.
Berners-Lee, et. al. Standards Track [Page 24]
RFC 2396 URI Generic Syntax August 1998
[RFC1736] Kunze, J., "Functional Recommendations for
Resource Locators", RFC 1736, February 1995.
[RFC2141] Moats, R., "URN Syntax", RFC 2141, May 1997.
[RFC1034] Mockapetris, P., "Domain Names - Concepts and Facilities",
STD 13, RFC 1034, November 1987.
[RFC2110] Palme, J., and A. Hopmann, "MIME E-mail Encapsulation
Aggregate Documents, such as HTML (MHTML)", RFC 2110,
1997.
[RFC1737] Sollins, K., and L. Masinter, "Functional Requirements
Uniform Resource Names", RFC 1737, December 1994.
[ASCII] US-ASCII. "Coded Character Set -- 7-bit American
Code for Information Interchange", ANSI X3.4-1986.
[UTF-8] Yergeau, F., "UTF-8, a transformation format of ISO 10646",
RFC 2279, January 1998.
Berners-Lee, et. al. Standards Track [Page 25]
RFC 2396 URI Generic Syntax August 1998
10. Authors'
Tim Berners-
World Wide Web
MIT Laboratory for Computer Science, NE43-356
545 Technology
Cambridge, MA 02139
Fax: +1(617)258-8682
EMail: timbl@w3.
Roy T.
Department of Information and Computer
University of California,
Irvine, CA 92697-3425
Fax: +1(949)824-1715
EMail: fielding@ics.uci.
Larry
Xerox
3333 Coyote Hill
Palo Alto, CA 94034
Fax: +1(415)812-4333
EMail: masinter@parc.xerox.
Berners-Lee, et. al. Standards Track [Page 26]
RFC 2396 URI Generic Syntax August 1998
A. Collected BNF for
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_no_slash = unreserved | escaped | ";" | "?" | ":" | "@" |
"&" | "=" | "+" | "$" | ","
net_path = "//" authority [ abs_path ]
abs_path = "/" path_
rel_path = rel_segment [ abs_path ]
rel_segment = 1*( unreserved | escaped |
";" | "@" | "&" | "=" | "+" | "$" | "," )
scheme = alpha *( alpha | digit | "+" | "-" | "." )
authority = server | reg_
reg_name = 1*( unreserved | escaped | "$" | "," |
";" | ":" | "@" | "&" | "=" | "+" )
server = [ [ userinfo "@" ] hostport ]
userinfo = *( unreserved | escaped |
";" | ":" | "&" | "=" | "+" | "$" | "," )
hostport = host [ ":" port ]
host = hostname | IPv4
hostname = *( domainlabel "." ) toplabel [ "." ]
domainlabel = alphanum | alphanum *( alphanum | "-" )
toplabel = alpha | alpha *( alphanum | "-" )
IPv4address = 1*digit "." 1*digit "." 1*digit "." 1*
port = *
path = [ abs_path | opaque_part ]
path_segments = segment *( "/" segment )
segment = *pchar *( ";" param )
param = *
pchar = unreserved | escaped |
":" | "@" | "&" | "=" | "+" | "$" | ","
query = *
fragment = *
Berners-Lee, et. al. Standards Track [Page 27]
RFC 2396 URI Generic Syntax August 1998
uric = reserved | unreserved |
reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
"$" | ","
unreserved = alphanum |
mark = "-" | "_" | "." | "!" | "~" | "*" | "'" |
"(" | ")"
escaped = "%" hex
hex = digit | "A" | "B" | "C" | "D" | "E" | "F" |
"a" | "b" | "c" | "d" | "e" | "f
alphanum = alpha |
alpha = lowalpha |
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"
Berners-Lee, et. al. Standards Track [Page 28]
RFC 2396 URI Generic Syntax August 1998
B. Parsing a URI Reference with a Regular
As described in Section 4.3, the generic URI syntax is not
to disambiguate the components of some forms of URI. Since
"greedy algorithm" described in that section is identical to
disambiguation method used by POSIX regular expressions, it
natural and commonplace to use a regular expression for parsing
potential four components and fragment identifier of a URI reference
The following line is the regular expression for breaking-down a
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.,
paired parenthesis). We refer to the value matched for
as $. For example, matching the above expression
http://www.ics.uci.edu/pub/ietf/uri/#
results in the following subexpression matches
$1 = http
$2 =
$3 = //www.ics.uci.
$4 = www.ics.uci.
$5 = /pub/ietf/uri
$6 =
$7 =
$8 = #
$9 =
where indicates that the component is not present, as
the case for the query component in the above example. Therefore,
can determine the value of the four components and fragment
scheme = $2
authority = $4
path = $5
query = $7
fragment = $9
and, going in the opposite direction, we can recreate a URI
from its components using the algorithm in step 7 of Section 5.2.
Berners-Lee, et. al. Standards Track [Page 29]
RFC 2396 URI Generic Syntax August 1998
C. Examples of Resolving