PHP如何头定位到页面的父目录?

问题描述 投票:8回答:3

我有一个first.php

header("Location: script/script1.php")

script1.php有另一个

header("Location: first.php") 

但它给我发显然是/script/first.php。有没有一种方法来重定向它<root>/first.php代替<root>/script/first.php

php header directory location
3个回答
18
投票

有这样的尝试:

header("Location: ../first.php")

或使用绝对路径或URL代替。

说明:..是用于“父目录”的Unix / Linux中表达。互联网是UNIX的土地,这样的规则适用也有。


1
投票

相反的:header("Location: ../first.php")

试试这个:header("url: ../first.php")

这将改变url.Using位置并不在某些情况下工作

因为:'../'是表示“父母directory'.So,这将工作。


1
投票

你可以这样做。在“0”秒重定向到主目录(根) -

<?php

     header('Refresh: 0, url = /Root_Dir/');

?>

您的目录名替换“ROOT_DIR”。

© www.soinside.com 2019 - 2024. All rights reserved.