HTTP 301重定向中的方案相对URI的支持程度如何 [英] How widely supported are scheme-relative URIs in HTTP 301 redirects
问题描述
我想要求 www
子域名或重定向到一个规范网址的备用顶级域名。
I want to have requests for the www
subdomain or for alternate top-level domains redirected to one canonical URL.
为了避免HTTP / HTTPS问题,我认为最简单的方法是在Location头中发送一个与方案相关的URI,如下所示:
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/
这似乎在浏览器中运行良好,但 http://no-www.org上的玩具»验证器« / 无法正确处理。这只是一个写得不好的脚本,或者这种行为在脚本,爬虫等中实际上更常见吗?
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?
推荐答案
位置 预计绝对URI:
Location expects an absolute URI:
[...]字段值由一个绝对URI组成。
[…] The field value consists of a single absolute URI.
Location = "Location" ":" absoluteURI
虽然大多数用户代理也会接受相对URI,但您应该遵守规范并提供绝对URI。
Although most user agents will also accept relative URIs, you should stick to the specification and provide an absolute URI.
这篇关于HTTP 301重定向中的方案相对URI的支持程度如何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!