2

我知道绝对路径 URL ( /path/to/resource) 是有效的,并且引用与当前资源相同的方案、主机、端口等。如果添加了相同(或不同!)的方案,该 URL 是否仍然有效?(http:/path/to/resourcehttps:/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 中进行测试:将鼠标悬停在链接上时显示的 URL 看起来正确。单击链接按预期工作。在 Web 检查器中查看 DOM,将鼠标悬停在a hrefURL 上会显示不正确的位置 ( /resource/number/one/http:/resource/number/two/)。

Firefox 38 似乎也能正确处理点击。奇怪的。

4

1 回答 1

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.

where特别是一条不以第一段不包含冒号path-noscheme开头的路径,它非常具体地解决了您的问题。/

于 2015-07-15T19:56:06.153 回答