我知道绝对路径网址(/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中进行测试:将鼠标悬停在链接上时显示的网址正确无误。单击该链接按预期工作。查看Web检查器中的DOM,将鼠标悬停在a href
网址上会显示错误的位置(/resource/number/one/http:/resource/number/two/
)。
Firefox 38似乎也正确处理了点击。怪异。
答案 0 :(得分:3)
不,它无效。来自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
特别是一个不以/
开头的路径,其第一段不包含冒号,这非常具体地解决了您的问题。