Common Internet Scheme Syntax
You may have already faced quite a common problem of setting absolute URIs to a resource on a page that must be accessed by both HTTPS and HTTP schemes.
RFC 1738 Common Internet Scheme Syntax section states the following:
While the syntax for the rest of the URL may vary depending on the particular scheme selected, URL schemes that involve the direct use of an IP-based protocol to a specified host on the Internet use a common syntax for the scheme-specific data:
So you don’t actually have to specify HTTP or HTTPS scheme, you just put two slashes and browser adds the current scheme automatically!
I tested this URL notation in the following browsers – IE3, IE4, IE5.0, IE501, IE5.5, IE6, IE7, IE8, FF2, FF3.0.8, Opera 8.5, Opera 9, Opera 10, Google Chrome (current version) – and it works fine in all of them!
You can test it yourself – here’s the testcase. As you may see, the URL is set without a scheme and your browser silently adds the current scheme! If you change http to https in your address, you’ll see that the scheme in dummy.html page URL will change to https!
It’s interesting to note that RFC 3986 (URI Generic Syntax) says that scheme part is required:
Each URI begins with a scheme name that refers to a specification for assigning identifiers within that scheme. As such, the URI syntax is a federated and extensible naming system wherein each scheme’s specification may further restrict the syntax and semantics of identifiers using that scheme.
, but mentions Common Internet Syntax notation in the Relative Reference section:
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.
However, I don’t think that any browser vendor will stop support for this functionality as it’s quite useful and there’s no problem in supporting it.
Bolk, thanks for sharing this!
UPDATE: Google and Nigma.ru said their robots would follow and index such a link.