Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URI starting with two slashes ... how do they behave?

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?

like image 457
pagid Avatar asked Nov 01 '10 16:11

pagid


People also ask

What does double slash in URL mean?

A double slash in the URL path is valid and will respond in the browser, but is typically unwelcome, as this could cause duplicate content issues if the CMS delivers the same content on two URLs (i.e. single slash and double slash).

What do you call slashes in URL?

An important part of a URL structure is the trailing slash at the end. This slash is often used to differentiate between a directory and a file on the website.


2 Answers

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.

like image 130
Daniel Vassallo Avatar answered Sep 21 '22 12:09

Daniel Vassallo


These are protocol relative URLs. They point to an address, keeping the current protocol.

This notation is often used to avoid the "mixed content" problem (a IE warning message complaining about http and https resources on the same HTTPS page).

Update: Official documentation in RFC 3986:

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.

like image 20
Pekka Avatar answered Sep 22 '22 12:09

Pekka