PHP 如何将标题定位到父目录中的页面?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13366217/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 05:15:26  来源:igfitidea点击:

PHP How to header-location to a page in a parent directory?

phpheaderdirectorylocation

提问by alecam

I have a first.phppage with

我有一个first.php页面

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

and script1.phphas another

script1.php有另一个

header("Location: first.php") 

but it sends me obviously to /script/first.php. Is there a way to redirect it to <root>/first.phpinstead of <root>/script/first.php?

但它显然将我发送到/script/first.php. 有没有办法将它重定向到<root>/first.php而不是<root>/script/first.php

回答by arkascha

have a try with this:

试试这个:

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

or use an absolute path or url instead.

或者改用绝对路径或 url。

Explanation: ..is the unix/linux expression used for 'parent directory'. The Internet is unix land, so that rules applies there too.

说明:..是用于“父目录”的 unix/linux 表达式。Internet 是unix 领域,因此规则也适用于那里。

回答by Kush Bhardwaj

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

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

try with this: header("url: ../first.php")

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

this will change the url.Using location don't work in some cases

这将更改 url.Using location 在某些情况下不起作用

Since: '../'is to denote 'parent directory'.So,this will work.

因为:'../'是表示“父目录”。所以,这将起作用。

回答by user7564487

You can do this. Redirects back to the Home directory (Root) in '0' seconds -

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

<?php

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

?>

Replace the 'Root_Dir' with your directory name.

将“Root_Dir”替换为您的目录名称。