Network-Path Reference URI / Scheme relative URLs

Scheme relative URLs (network-path references) are something that I've just found out about - where you don't specify the scheme of a URL and it picks it up from the current context.

For example: will resolve to https://domain.com/img.png if the current scheme is HTTPS or http://domain.com/img.png if it is not.

This seems like a very easy way to resolve those pesky problems of calling an external script or image on an SSL page without bringing up the dreaded error that some content on a page is not secure.

The benefit seems obvious, but what I don't seem to be able to find is a huge amount of information on this and was wondering if anyone had any experience or references about scheme relative URLs (good or bad)?

Whilst I'm trying to discover if there are any browsers that this causes issues with (I've been successful with IE6-8, Chrome and Firefox), I'm also interested to find out if anyone has any experience using this in different languages. For example, would it work if you were to issue a Response.Redirect with a scheme relative URL in ASP?

60
задан unor 22 January 2014 в 21:00
поделиться

1 ответ

//domain.com/img.png — это абсолютно допустимый синтаксис URI согласно RFC 3986: раздел 4.2.

Это относительно текущей схемы, и поэтому, как вы упомянули, может быть очень полезно при переключении между http и https, потому что вам не нужно явно указывать схему.

Все современные браузеры понимают этот формат, включая IE 6.

Дополнительная информация о переполнении стека: