Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the Location header accept the // protocol notation?

Tags:

http

Most if not all browsers support the following notation:

<script src="//domain.com/script.js">

The // notation means use the same protocol as the current one, i.e.:

  • http://domain.com/script.js if the current page has been served over HTTP
  • https://domain.com/script.js if the current page has been served over HTTPS

This notation works with other HTML tags as well: <a>, <link>, etc.

Is this notation also valid for the Location header?

For example, is it valid to reply this:

HTTP/1.0 301 Moved Permanently
Location: //domain.com/other-resource
like image 551
BenMorel Avatar asked Dec 05 '25 13:12

BenMorel


1 Answers

A URL starting with // is an example of a relative URL.

The Location-header needs an absolute URL, which means the answer you are looking for unfortunately is: no, it's not supported.

This is specified in Section 14.30 of RFC2616 on HTTP/1.1:

The field value consists of a single absolute URI.


Edit: But please consider the comments attached to this answer. My answer should maybe have been qualified by "according to the currently accepted published standard" or something. I am not the one to ask about what exists in reality ;)

like image 178
Magnus Hoff Avatar answered Dec 08 '25 20:12

Magnus Hoff