URI 以两个斜杠开头……它们的行为如何? [英] URI starting with two slashes ... how do they behave?

查看:41
本文介绍了URI 以两个斜杠开头……它们的行为如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我看到工作这样的代码块:

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

并且根据 RFC 2396(URI 语法)和 RFC 2616(HTTP 1.1),这些以两个斜杠开头的 URI 是有效的,但不幸的是 RFC 并没有真正解释它们.

谁能给我指出一个解释浏览器将/应该/如何处理这些 URI 的资源?

解决方案

您正在寻找的资源是 RFC 3986.

请参阅第 4.2 节和第 5.4 节.引用后者:

<块引用>

参考解析示例

在具有明确定义的基本 URI 的表示中:

 http://a/b/c/d;p?q

<块引用>

一个相对引用被转换为它的目标 URI,如下所示:

 "g:h" = "g:h""g" = "http://a/b/c/g""./g" = "http://a/b/c/g""g/" = "http://a/b/c/g/""/g" = "http://a/g""//g" = "http://g""?y" = "http://a/b/c/d;p?y""g?y" = "http://a/b/c/g?y""#s" = "http://a/b/c/d;p?q#s""g#s" = "http://a/b/c/g#s""g?y#s" = "http://a/b/c/g?y#s"";x" = "http://a/b/c/;x""g;x" = "http://a/b/c/g;x""g;x?y#s" = "http://a/b/c/g;x?y#s""" = "http://a/b/c/d;p?q"."= "http://a/b/c/""./" = "http://a/b/c/"".." = "http://a/b/""../" = "http://a/b/""../g" = "http://a/b/g""../.." = "http://a/""../../" = "http://a/""../../g" = "http://a/g"

这意味着当基本 URI 是 http://a/b/c/d;p?q 并且您使用 //g 时,相对引用转换为http://g.

Lately I saw working code-blocks like this:

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

And according to RFC 2396 (URI Syntax) and RFC 2616 (HTTP 1.1) these URI starting with two slashes are valid, but unfortunately the RFCs don't really explain them.

Can anyone point me to a resource which explains how browsers will/should/do process these URIs?

解决方案

The resource you're looking for is the RFC 3986.

See Section 4.2 and Section 5.4. Quoting from the latter:

Reference Resolution Examples

Within a representation with a well defined base URI of:

    http://a/b/c/d;p?q

a relative reference is transformed to its target URI as follows:

  "g:h"           =  "g:h"
  "g"             =  "http://a/b/c/g"
  "./g"           =  "http://a/b/c/g"
  "g/"            =  "http://a/b/c/g/"
  "/g"            =  "http://a/g"
  "//g"           =  "http://g"
  "?y"            =  "http://a/b/c/d;p?y"
  "g?y"           =  "http://a/b/c/g?y"
  "#s"            =  "http://a/b/c/d;p?q#s"
  "g#s"           =  "http://a/b/c/g#s"
  "g?y#s"         =  "http://a/b/c/g?y#s"
  ";x"            =  "http://a/b/c/;x"
  "g;x"           =  "http://a/b/c/g;x"
  "g;x?y#s"       =  "http://a/b/c/g;x?y#s"
  ""              =  "http://a/b/c/d;p?q"
  "."             =  "http://a/b/c/"
  "./"            =  "http://a/b/c/"
  ".."            =  "http://a/b/"
  "../"           =  "http://a/b/"
  "../g"          =  "http://a/b/g"
  "../.."         =  "http://a/"
  "../../"        =  "http://a/"
  "../../g"       =  "http://a/g"

This means that when the base URI is http://a/b/c/d;p?q and you use //g, the relative reference is transformed to http://g.

这篇关于URI 以两个斜杠开头……它们的行为如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆