URL containing a scheme but no permissions (hostname)?

Is it legal (and good practice and well supported) to omit the authority component from a URL (usually a host name), but specify a scheme (usually http: or https: ?

For example, are these valid URLs?

  https:login.html (relative hostname and path) https:/auth/login.html (relative hostname, absolute path) 

The expected behavior, of course, will be to use the current host name - the path (relative).

(BTW, this assumes // after this scheme is part of the authority (host) component, I think this is the correct intuition)

Motivation is a general requirement that some pages of a website be accessible via https and others via http, and we would like to use relative URLs instead of an absolute one (for testing in different environments).

+4
source share
2 answers

In accordance with RFC1738, double slashes // are part of the specific protocol (scheme) data (therefore, they are not mandatory in accordance with this document).

However, the HTTP protocol ( RFC2616 ) in 3.2.2 makes a double slash of the scheme, so it is required. There is no valid HTTP URL without them.

From RFC2616 3.2.1:

HTTP URIs can be represented in absolute form or relative [...]. The two forms are differentiated by the fact that absolute URIs always begin with the name of the scheme, followed by a colon.

... so if you specify a scheme, then it is already considered an absolute URI.

+3
source

After reading some sources, I think the corresponding link is RFC1808

It is explicitly stated here that if a schema name is specified, then the URL is considered to be absolute.

He also comments (5.2) that RFC1630 resolved some relative URL with the name of the scheme, but:

  • the schema name must be the same as the current (base) one and will be ignored
  • this behavior was only implemented in older browsers
  • he is out of date

In conclusion, the above URLs are invalid.

0
source

Source: https://habr.com/ru/post/1346937/


All Articles