问题
I want to have requests for the www subdomain or for alternate top-level domains redirected to one canonical URL.
To avoid HTTP/HTTPS issues, I figured the easiest way would be to just send a scheme-relative URI in the Location header, like so:
HTTP/1.1 301 Moved Permanently
Location: //example.com/
This seems to work fine in browsers, but the toy »validator« at http://no-www.org/ does not handle it correctly. Is this just a single badly written script, or is this behavior actually more common in scripts, crawlers, etc. out there?
回答1:
Location expects an absolute URI:
[…] The field value consists of a single absolute URI.
Location = "Location" ":" absoluteURI
Although most user agents will also accept relative URIs, you should stick to the specification and provide an absolute URI.
来源:https://stackoverflow.com/questions/4387289/how-widely-supported-are-scheme-relative-uris-in-http-301-redirects