How widely supported are scheme-relative URIs in HTTP 301 redirects

半城伤御伤魂 提交于 2019-12-11 03:39:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!