只有方案 + 路径的 URL 有效吗?
Is a URL with only scheme + path valid?
我知道仅绝对路径 URLs (/path/to/resource
) 是有效的,并且指的是与当前资源相同的方案、主机、端口等。如果添加相同(或不同!)方案,URL 是否仍然有效? (http:/path/to/resource
或 https:/path/to/resource
)
如果它 根据规范的字母是有效的,浏览器处理它的效果如何?未来可能会遇到代码的开发人员如何处理它?
附录:
这是我在 Apache 服务器上设置的一个简单测试用例:
resource/number/one/index.html
:
<a href="http:/resource/number/two/">link</a>
resource/number/two/index.html
:
two
在 OS X 上 Chrome 43 中进行测试:将鼠标悬停在 link 上时显示的 URL 看起来是正确的。单击 link 按预期工作。查看 Web 检查器中的 DOM,将鼠标悬停在 a href
URL 上会显示不正确的位置 (/resource/number/one/http:/resource/number/two/
)。
Firefox 38 似乎也能正确处理点击。奇怪。
不,无效。来自 RFC 3986:
4.2. Relative Reference
A relative reference takes advantage of the hierarchical syntax
(Section 1.2.3) to express a URI reference relative to the name space
of another hierarchical URI.
relative-ref = relative-part [ "?" query ] [ "#" fragment ]
relative-part = "//" authority path-abempty
/ path-absolute
/ path-noscheme
/ path-empty
The URI referred to by a relative reference, also known as the target
URI, is obtained by applying the reference resolution algorithm of
Section 5.
A relative reference that begins with two slash characters is termed
a network-path reference; such references are rarely used. A
relative reference that begins with a single slash character is
termed an absolute-path reference. A relative reference that does
not begin with a slash character is termed a relative-path reference.
A path segment that contains a colon character (e.g., "this:that")
cannot be used as the first segment of a relative-path reference, as
it would be mistaken for a scheme name. Such a segment must be
preceded by a dot-segment (e.g., "./this:that") to make a relative-
path reference.
其中 path-noscheme
特别是一条不以 /
开头的路径,其第一段不包含冒号,这非常具体地解决了您的问题。
我知道仅绝对路径 URLs (/path/to/resource
) 是有效的,并且指的是与当前资源相同的方案、主机、端口等。如果添加相同(或不同!)方案,URL 是否仍然有效? (http:/path/to/resource
或 https:/path/to/resource
)
如果它 根据规范的字母是有效的,浏览器处理它的效果如何?未来可能会遇到代码的开发人员如何处理它?
附录:
这是我在 Apache 服务器上设置的一个简单测试用例:
resource/number/one/index.html
:
<a href="http:/resource/number/two/">link</a>
resource/number/two/index.html
:
two
在 OS X 上 Chrome 43 中进行测试:将鼠标悬停在 link 上时显示的 URL 看起来是正确的。单击 link 按预期工作。查看 Web 检查器中的 DOM,将鼠标悬停在 a href
URL 上会显示不正确的位置 (/resource/number/one/http:/resource/number/two/
)。
Firefox 38 似乎也能正确处理点击。奇怪。
不,无效。来自 RFC 3986:
4.2. Relative Reference
A relative reference takes advantage of the hierarchical syntax
(Section 1.2.3) to express a URI reference relative to the name space
of another hierarchical URI.
relative-ref = relative-part [ "?" query ] [ "#" fragment ]
relative-part = "//" authority path-abempty
/ path-absolute
/ path-noscheme
/ path-empty
The URI referred to by a relative reference, also known as the target
URI, is obtained by applying the reference resolution algorithm of
Section 5.
A relative reference that begins with two slash characters is termed
a network-path reference; such references are rarely used. A
relative reference that begins with a single slash character is
termed an absolute-path reference. A relative reference that does
not begin with a slash character is termed a relative-path reference.
A path segment that contains a colon character (e.g., "this:that")
cannot be used as the first segment of a relative-path reference, as
it would be mistaken for a scheme name. Such a segment must be
preceded by a dot-segment (e.g., "./this:that") to make a relative-
path reference.
其中 path-noscheme
特别是一条不以 /
开头的路径,其第一段不包含冒号,这非常具体地解决了您的问题。