如何从 Location header 构建 URI?

How the URI on constructed from Location header?

对“http://fakedomain.com/my/abc/redirect.php?url=www.example.com”URL 的 GET 请求导致以下响应 header、

HTTP/1.1 302 Found
Date: Mon, 30 Apr 2018 07:39:12 GMT
Server: Apache/2.2.15 (CentOS)
X-Powered-By: PHP/5.3.3
Location: www.example.com
Content-Length: 40
Connection: close
Content-Type: text/html; charset=UTF-8

服务器 prepare/User 代理如何从该位置 header.

准备 URL

是否将重定向请求发送到“www.example.com”? 或者 它是否将重定向请求发送到“http://fakedomain.com/my/abc/www.example.com”?

为什么它会 URL 那样?

Does it send redirect request to www.example.com? Or does it send redirect request to http://fakedomain.com/my/abc/www.example.com?

请求应该重定向到 http://fakedomain.com/my/abc/www.example.com

RFC 7231 says the following regarding the Locationheader(高亮是我的):

7.1.2. Location

The Location header field is used in some responses to refer to a specific resource in relation to the response. The type of relationship is defined by the combination of request method and status code semantics.

 Location = URI-reference

The field value consists of a single URI-reference. [...]

URI-reference concept is define as follows in the RFC 3986(高亮是我的):

4.1. URI Reference

URI-reference is used to denote the most common usage of a resource identifier.

 URI-reference = URI / relative-ref

A URI-reference is either a URI or a relative reference. If the URI-reference's prefix does not match the syntax of a scheme followed by its colon separator, then the URI-reference is a relative reference. [...]

所以 www.example.com 应该解释为 relative reference and not as an absolute URI.

www.example.com 情况被描述为 suffix reference in the RFC 3986:它与 relative-path 引用具有相同的语法,不能在需要相对引用的上下文中使用(重点是我的):

4.5. Suffix Reference

The URI syntax is designed for unambiguous reference to resources and extensibility via the URI scheme. However, as URI identification and usage have become commonplace, traditional media (television, radio, newspapers, billboards, etc.) have increasingly used a suffix of the URI as a reference, consisting of only the authority and path portions of the URI, such as

 www.w3.org/Addressing/

or simply a DNS registered name on its own. Such references are primarily intended for human interpretation rather than for machines, with the assumption that context-based heuristics are sufficient to complete the URI (e.g., most registered names beginning with www are likely to have a URI prefix of http://). Although there is no standard set of heuristics for disambiguating a URI suffix, many client implementations allow them to be entered by the user and heuristically resolved.

Although this practice of using suffix references is common, it should be avoided whenever possible and should never be used in situations where long-term references are expected. The heuristics noted above will change over time, particularly when a new URI scheme becomes popular, and are often incorrect when used out of context. [...]

As a URI suffix has the same syntax as a relative-path reference, a suffix reference cannot be used in contexts where a relative reference is expected. As a result, suffix references are limited to places where there is no defined base URI, such as dialog boxes and off-line advertisements.