HTTP 301 重定向中方案相关 URI 的支持范围有多广
我希望将对 www
子域或备用顶级域的请求重定向到一个规范 URL。
为了避免 HTTP/HTTPS 问题,我认为最简单的方法是在 Location 标头中发送一个相对于方案的 URI,如下所示:
HTTP/1.1 301 Moved Permanently
Location: //example.com/
这似乎在浏览器中工作正常,但是 http://no-www.org/ 无法正确处理它。这只是一个写得不好的脚本,还是这种行为实际上在脚本、爬虫等中更常见?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
位置需要绝对值网址:
尽管大多数用户代理也接受相对 URI,但您应该遵守规范并提供绝对 URI。
Location expects an absolute URI:
Although most user agents will also accept relative URIs, you should stick to the specification and provide an absolute URI.