PHP How is the heading location on a page in the parent directory?

I have a first.php page with

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

and script1.php has another

 header("Location: first.php") 

but it explicitly passes me /script/first.php . Is there a way to redirect it to <root>/first.php instead of <root>/script/first.php ?

+7
source share
3 answers

try with this:

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

or use an absolute path or url.

Explanation: .. is the unix / linux expression used for the "parent directory". The Internet is unix-land, so the rules apply.

+12
source

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

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

this will change url.Using does not work in some cases

Since: '../' means "parent directory". This way it will work.

+1
source

Can you do this. Redirects back to the home directory (Root) in "0" seconds -

 <?php header('Refresh: 0, url = /Root_Dir/'); ?> 

Replace "Root_Dir" with the name of your directory.

+1
source

All Articles