在 Apache 级别解决设置规则时,发现 php 中的 header('Location: filename.php') 覆盖了响应代码。看下面的代码:-
<?php
header('HTTP/1.1 308 Permanent Redirect'); //or Try for 4xx/5xx Code
header('Location: http://hello.php');
?>
Expected result
- HTTP/1.1 308 永久重定向
- 主机:本地主机:8000
- 位置:hello.php
- 连接:关闭
- X-Powered-By: PHP/5.5.6
Actual result
- HTTP/1.1
302 Found
- 主机:本地主机:8000
- 位置:hello.php
- 连接:关闭
- X-Powered-By: PHP/5.5.6
Apache 级别有问题还是 PHP 中有错误?
Update:
As per 函数文档页面 http://php.net/manual/en/function.header.php这是 PHP 在发送 Location 标头时所需的行为。
编辑:抱歉,误读了您的消息。如果您发送的代码不同于 3xx,它将覆盖响应代码,因此它应该适用于 308。
您确定没有发回其他 HTTP 代码吗?您的客户是否尝试检索新资源并且您看到 302 作为最终结果?
最终编辑:你尝试过吗
header('Location: /some/page.php', TRUE, 308);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)