Is it legal (and good practice, and well supported) to omit the "authority" component from a URL (typically the hostname) but specify a scheme (typically 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 behaviour, of course, would be to use the current hostname - path (relative).
(BTW, this assumes that the //
after the scheme is part of the authority (host) component, I think this is the right intepretation)
The motivation is the (common) requirement that some pages of a website are to be accesed via https and other via http, and we'd like to use relative urls instead of absolute (to test in different environments).
According to RFC1738 the double slashes //
are part of the protocol (scheme) specific data (so they are not compulsory according to this document).
But the HTTP protocol (RFC2616) in 3.2.2 makes the double slashes part of the scheme, so it's a must. No valid HTTP URL without them.
From RFC2616 3.2.1:
URIs in HTTP can be represented in absolute form or relative [ ... ] The two forms are differentiated by the fact that absolute URIs always begin with a scheme name followed by a colon.
... so if you specify the scheme then it already is considered an absolute URI.
According to RFC 3986:
+.-
//
is part of the Authority
So:
scheme:
//authority
/path
This means
https://stackoverflow.com/auth/login.html
\____/\_________________/\______________/
| | |
scheme authority path
The Authority is optional, which means the following is also valid:
https:/auth/login.html
\____/\______________/
| |
scheme path
The RFC notes another rule:
//
/
To sum up:
https://stackoverflow.com/auth/login.html
(valid)
https:///auth/login.html
(invalid; path cannot begin with // when no authority present)
https://auth/login.html
(invalid; path cannot begin with // when no authority present)
https:/auth/login.html
(valid)
https:auth/login.html
(valid)
https:/login.html
(valid)
https:login.html
(valid)
https:/
(valid)
https:
(valid)
https:login.html
: Yeshttps:/auth/login.html
YesIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With