在“位置:”中使用协议相对URI。头 [英] Using protocol-relative URIs within "Location:" headers

查看:142
本文介绍了在“位置:”中使用协议相对URI。头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 PHP手册中注明了以下内容:

I note in the PHP manual which states the following:


HTTP / 1.1需要绝对URI作为参数来»位置:包括
方案,主机名和绝对路径,但有些客户接受
相对URI。

HTTP/1.1 requires an absolute URI as argument to » Location: including the scheme, hostname and absolute path, but some clients accept relative URIs.

为了方便用户优先选择无处不在的HTTPS连接,我正在考虑改变我的PHP脚本中的标题:

To facilitate users with preference for a HTTPS everywhere connection, I am thinking of changing the headers in my PHP scripts from:

header(Location:http://www.example.com/); to header(Location://www.example.com/) ;

我已经测试了上面的代码在我的firefox浏览器上工作,但我不确定这是否是明智的做法。或者我是否应该从 $ _ SERVER 变量中提取协议并将其放入。

I have tested the above code to be working on my firefox browser, but I am not sure whether it is an advisable thing to do. Or whether I should extract the protocol from $_SERVER variable and put it in.

推荐答案

HTTPbis更新允许相对URI。虽然没有特别提及,但这包括协议相对URL。

The HTTPbis update allows relative URIs. While not specifically mentioned, this includes protocol-relative URLs.

(最重要的是对文档建立的浏览器行为的HTTP / 1.1规范的更新。)

(It's foremost an update to the HTTP/1.1 spec that documents established browser behaviour.)

这篇关于在“位置:”中使用协议相对URI。头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆