Sharovatov’s Weblog

Common Internet Scheme Syntax

Posted in browsers, http by sharovatov on 17 April 2009

Recently read an extremely interesting post on about “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 said their robots would follow and index such a link.


Tagged with: , , ,

2 Responses

Subscribe to comments with RSS.

  1. Andy Duncan said, on 7 October 2009 at 10:28 pm

    This is seriously not getting enough attention. Everyone I’ve shown this to is blown away. I’m half amazed at it and half embarrassed by the fact that I didn’t know you could do this.

    E-mail me if you’re ever in LA, I owe you cases upon cases of beer.

  2. sharovatov said, on 8 October 2009 at 4:50 am

    Thanks Andy :) Glad it was interesting!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: