带有相对路径的位置标头没有重定向


Location header with relative path not re-directing

我的头标签没有正确重定向,我不知道为什么。这是我的台词:

header('Location:../destination.php');

文件位于:www.example.com/one/two/example.php

现在,如果我进入页面并立即重定向(它应该)它加载www.example.com/one/two/example/destination.php而不是www.example.com/one/destination.php

它只是将destination.php添加到当前路径。很奇怪。

试试这个:

header("Location: //www.example.com/one/destination.php");

我使用了一个无模式的URI,因为问题没有指定您使用的是http://还是https://

虽然可以接受相对路径,但规范要求使用绝对uri。我将依靠它来保持一致性。

14.30位置

Location response-header字段用于重定向接收方到request - uri以外的位置以完成请求或新资源的标识。

字段值由单个绝对URI组成。

   Location       = "Location" ":" absoluteURI