📄 rfc1808.txt
字号:
listed in the order in which they would be applied by the parser.
2.4.1. Parsing the Fragment Identifier
If the parse string contains a crosshatch "#" character, then the
substring after the first (left-most) crosshatch "#" and up to the
end of the parse string is the <fragment> identifier. If the
crosshatch is the last character, or no crosshatch is present, then
the fragment identifier is empty. The matched substring, including
the crosshatch character, is removed from the parse string before
continuing.
Note that the fragment identifier is not considered part of the URL.
However, since it is often attached to the URL, parsers must be able
to recognize and set aside fragment identifiers as part of the
process.
2.4.2. Parsing the Scheme
If the parse string contains a colon ":" after the first character
and before any characters not allowed as part of a scheme name (i.e.,
any not an alphanumeric, plus "+", period ".", or hyphen "-"), the
<scheme> of the URL is the substring of characters up to but not
including the first colon. These characters and the colon are then
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 and 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 is assigned to <net_loc>. The double-
slash and <net_loc> are removed from the parse string before
Fielding Standards Track [Page 6]
RFC 1808 Relative Uniform Resource Locators June 1995
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 "?" and up to the
end of the parse string is the <query> information. If the question
mark is the last character, or no question mark is present, then the
query information is empty. The matched substring, including the
question mark character, is removed from the parse string before
continuing.
2.4.5. Parsing the Parameters
If the parse string contains a semicolon ";" character, then the
substring after the first (left-most) semicolon ";" and up to the end
of the parse string is the parameters (<params>). If the semicolon
is the last character, or no semicolon is present, then <params> is
empty. The matched substring, including the semicolon character, is
removed from the parse string before continuing.
2.4.6. Parsing the Path
After the above steps, all that is left of the parse string is the
URL <path> and the slash "/" that may precede it. Even though the
initial slash is not part of the URL path, the parser must remember
whether or not it was present so that later processes can
differentiate between relative and absolute paths. Often this is
done by simply storing the preceding slash along with the path.
3. Establishing a Base URL
The term "relative URL" implies that there exists some absolute "base
URL" against which the relative reference is applied. Indeed, the
base URL is necessary to define the semantics of any embedded
relative URLs; without it, a relative reference is meaningless. In
order for relative URLs to be usable within a document, the base URL
of that document must be known to the parser.
Fielding Standards Track [Page 7]
RFC 1808 Relative Uniform Resource Locators June 1995
The base URL of a document can be established in one of four ways,
listed below in order of precedence. The order of precedence can be
thought of in terms of layers, where the innermost defined base URL
has the highest precedence. This can be visualized graphically as:
.----------------------------------------------------------.
| .----------------------------------------------------. |
| | .----------------------------------------------. | |
| | | .----------------------------------------. | | |
| | | | (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 of the document can
be embedded within the content itself such that it can be readily
obtained by a parser. This can be useful for descriptive documents,
such as tables of content, which may be transmitted to others through
protocols other than their usual retrieval context (e.g., E-Mail or
USENET news).
It is beyond the scope of this document to specify how, for each
media type, the base URL can be embedded. It is assumed that user
agents manipulating such media types will be able to obtain the
appropriate syntax from that media type's specification. An example
of how the base URL can be embedded in the Hypertext Markup Language
(HTML) [3] is provided in an Appendix (Section 10).
Messages are considered to be composite documents. The base URL of a
message can be specified within the message headers (or equivalent
tagged metainformation) of the message. For protocols that make use
of message headers like those described in RFC 822 [5], we recommend
that the format of this header be:
base-header = "Base" ":" "<URL:" absoluteURL ">"
where "Base" is case-insensitive and any whitespace (including that
used for line folding) inside the angle brackets is ignored. For
example, the header field
Fielding Standards Track [Page 8]
RFC 1808 Relative Uniform Resource Locators June 1995
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 both the base for any relative URLs within the message
headers and the default base URL for documents enclosed within the
message, as described in the next section.
Protocols which do not use the RFC 822 message header syntax, but
which do allow some form of tagged metainformation to be included
within messages, may define their own syntax for defining 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 that is enclosed
within another entity (such as a message or another document), the
retrieval context is that entity; thus, the default base URL of the
document is the base URL of the entity in which the document is
encapsulated.
Composite media types, such as the "multipart/*" and "message/*"
media types defined by MIME (RFC 1521, [4]), define a hierarchy of
retrieval context for their enclosed documents. In other words, the
retrieval context of a component part is the base URL of the
composite entity of which it is a part. Thus, a composite entity can
redefine the retrieval context of its component parts via the
inclusion of a base-header, and this redefinition applies recursively
for a hierarchy of composite parts. 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 is not encapsulated
within some other entity (e.g., 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. Note that if the retrieval was the
result of a redirected request, the last URL used (i.e., that which
resulted in the actual retrieval of 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.
Fielding Standards Track [Page 9]
RFC 1808 Relative Uniform Resource Locators June 1995
It is the responsibility of the distributor(s) of a document
containing relative URLs to ensure that 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
This section describes an example algorithm for resolving URLs within
a context in which the URLs may be relative, such that the result is
always a URL in absolute form. Although this algorithm cannot
guarantee that the resulting URL will equal that intended by the
original author, it does guarantee that any valid URL (relative or
absolute) can be consistently transformed to an 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.
Fielding Standards Track [Page 10]
RFC 1808 Relative Uniform Resource Locators June 1995
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.
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.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -