问题
I have a first.php page with
header("Location: script/script1.php")
and script1.php has another
header("Location: first.php")
but it sends me obviously to /script/first.php.
Is there a way to redirect it to <root>/first.php instead of <root>/script/first.php?
回答1:
have a try with this:
header("Location: ../first.php")
or use an absolute path or url instead.
Explanation: .. is the unix/linux expression used for 'parent directory'. The Internet is unix land, so that rules applies there too.
回答2:
Instead of:
header("Location: ../first.php")
try with this:
header("url: ../first.php")
this will change the url.Using location don't work in some cases
Since: '../' is to denote 'parent directory'.So,this will work.
回答3:
You can do this. Redirects back to the Home directory (Root) in '0' seconds -
<?php
header('Refresh: 0, url = /Root_Dir/');
?>
Replace the 'Root_Dir' with your directory name.
来源:https://stackoverflow.com/questions/13366217/php-how-to-header-location-to-a-page-in-a-parent-directory