You can do this (relative addressing):

header("location: ../dashboard.php"); // for one folder
header("location: ../../dashboard.php"); // for two folders
Answer from Saqib Amin on Stack Overflow
🌐
PHP
php.net › manual › en › function.header.php
PHP: header - Manual
Browsers typically re-request a 307 page every time, cache a 302 page for the session, and cache a 301 page for longer, or even indefinitely. Search engines typically transfer "page rank" to the new location for 301 redirects, but not for 302, 303 or 307. If the status code is not specified, header('Location:') defaults to 302.
Discussions

PHP How to header-location to a page in a parent directory? - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
🌐 stackoverflow.com
Path to folder - PHP - SitePoint Forums | Web Development & Design Community
Hello. I have a file login that redirects to the login page if the user enters the correct details. header('Location:./employers/welcome_member.php'); The location of the file is in the folder “employers” how can specify the path to that folder? Thanks More on sitepoint.com
🌐 sitepoint.com
0
April 25, 2015
http redirect - PHP header(Location: ...): Force URL change in address bar - Stack Overflow
I'm currently working on a mobile site with authentication using PHP sessions with a database. I have a login page with a form that goes to server_login.php on submit. The php file then creates some More on stackoverflow.com
🌐 stackoverflow.com
php - Header Location relative path compatibility - Stack Overflow
How else do you think it decides to change its location? ... @11684 Your wrong. PHP is executed on the server, yes. But PHP send the header to the browser (client) and the client do whatever he want with it. ... John V. – John V. 2012-05-10 20:31:51 +00:00 Commented May 10, 2012 at 20:31 ... But to answer your question, yes it will redirect to the page X in the current folder ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Edureka
edureka.co › blog › header-location-in-php
Header Location In PHP | PHP Header Location Edureka
February 25, 2025 - It must be called before sending any actual output, either by normal HTML tags, blank lines in a file or from a PHP file. Syntax: header(string,replace,http_response_code); string: It consists of a header string. Basically, there are two types of header calls. One is header which starts with string “HTTP/” used to figure out the HTTP status code to send. Another one is the “Location” which is mandatory.
🌐
SitePoint
sitepoint.com › php
Path to folder - PHP - SitePoint Forums | Web Development & Design Community
April 25, 2015 - Hello. I have a file login that redirects to the login page if the user enters the correct details. header('Location:./employers/welcome_member.php'); The location of the file is in the folder “employers” how can speci…
🌐
Position Is Everything
positioniseverything.net › home › php header location: how header function fulfills different purposes?
PHP Header Location: How Header Function Fulfills Different Purposes? - Position Is Everything
December 29, 2025 - The PHP header location is a function implementation that allows you to redirect to another webpage or website. You can specify either an absolute path, a relative path, or a website URL for redirection.
Find elsewhere
🌐
HubSpot
blog.hubspot.com › home › website › how to redirect in php: what you need to know
How to Redirect in PHP: What You Need to Know
July 28, 2022 - To create a PHP redirect, you first need to write your header() function. This begins with header(). Next, define the Location response-header field with the URL or file name where you want to redirect users and search engines.
Top answer
1 of 2
15
header("Location: http://".$_SERVER['HTTP_HOST'].$formaction;

location should contain URL, not server file path

2 of 2
1

You could theoretically create a PHP File at the Root of your Application and call it anything you like: say redirect.php. Then inside of this redirect.php, you could put some code that might look something like this:

<?php
    // CREATE AN ARRAY THAT WITH NUMERIC KEY
    // THAT WILL CORRESPOND TO THE FILE YOU WISH TO REDIRECT TO (ACTUALLY LOAD)
    // SINCE THIS IS A PSEUDO REDIRECT:
    $fileMap            = array(
        0   => "./file-1.php",
        1   => "./file-2.php",
        2   => "./file-3.php",
        3   => "./file-4.php",
        4   => "./file-5.php",
        5   => "./file-6.php",
        6   => "/cert/forms/sessions/session-inc-info.php",
        7   => "./../../session-inc-info.php",  //<== YOU MAY KEEP ADDING TO LIST
    );

    // CHECK THAT THERE IS A GET PARAM WITH NAME: to
    if(isset($_GET['to'])){
        $fileKey        = $_GET['to'];          //<== GET THE `to` PARAM FROM $_GET
        $loadableFile   = $fileMap[$fileKey];   //<== TRANSLATE `to` KEY TO A LOADABLE FILE

        // IF THE FILE [$loadableFile] EXISTS, LOAD IT
        // OTHERWISE REDIRECT TO MAIN-APPLICATION PAGE (HOMEPAGE)
        if(file_exists($loadableFile)){
            require_once $loadableFile;
        }else{
            header("location: index.php");      //<== ASSUMES index.php IS THE MAIN FILE.
            exit;
        }
    }

    // IF ALL FAILS, STILL REDIRECT TO THE MAIN-APPLICATION PAGE
    header("location: index.php");              //<== ASSUMES index.php IS THE MAIN FILE.

Then on each page where you wish to Perform a redirect, you may simply do something like this:

<?php
    // ASSUMING YOU WANT TO RE-DIRECT TO: `./../../session-inc-info.php`
    // AS YOU CAN SEE FROM THE `$fileMap` ARRAY, `./../../session-inc-info.php`
    // HAS THE KEY OF "7"
    // NOW ALL YOU CAN DO IS SIMPY APPEND "?to=7" TO `redirect.php` 
    // IN THE `header()` METHOD LIKE THIS:
    header("location: redirect.php?to=7"); 
    exit;
    /*EXPECTED TO LOAD THE FILE: `./../../session-inc-info.php`

NOTE:
This is not really a Redirect (as it is basically just loading[including] Files from a given Location/Path, however since it seems you are trying to load some file like: /cert/forms/sessions/session-inc-info.php, it is assumed that this may be an option. To do a real Redirect: just use the header() Function directly passing it the exact URL-Location to which to redirect.

Cheers and Good-Luck...

🌐
Google Groups
groups.google.com › g › alt.php › c › E3x8jr9gofQ
using a header-file with links in it over multiple folders
I somehow have to dynamically create the links in the header by checking paths/folders etc. but don't know how to approach this. ... Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message ... One way is to use ... ... Do a .. <?php echo ("$_SERVER[DOCUMENT_ROOT]/header.php"); ?> ..to check the path.
🌐
bodHOST
bodhost.com › tutorial › what is a php header redirect and how to create one
What is a PHP Header Redirect and How to Create One
September 4, 2025 - <?php // Relative URL redirect header("Location: /folder/anotherPage.php"); exit; ?>
🌐
YouTube
youtube.com › leon marsden
php - Redirects to control visible pages with header("Location:index.php") - YouTube
In this tutorial, we will look at the redirect command using header("Location:index.php"); to redirect a user if they have not logged into the system. This c...
Published   August 6, 2019
Views   2K
🌐
SitePoint
sitepoint.com › php
The header('Location') code - PHP - SitePoint Forums | Web Development & Design Community
September 13, 2010 - Just for reference, the RFC(2616) states you should use an absolute address(URI) for the Location header, not a relative one. ... I imagine the “.” is like in directory searching, one means “this directory” and two means “parent directory”. So “Location: .” would mean go to this directory and then whatever the directory’s default “index” page is would be the one that’s served. ... It is the most effective way to reload the default page in the current directory. In the PHP Live course and in his books on PHP Kevin recommends a structure of one page per directory and the use of that statement whenever the page needs to be reloaded.
🌐
Our Code World
ourcodeworld.com › articles › read › 252 › how-to-redirect-to-a-page-with-plain-php
How to redirect to a page with plain PHP | Our Code World
September 15, 2016 - function redirect($url, $permanent = false){ if (headers_sent() === false) { header('Location: ' . $url, true, ($permanent === true) ? 301 : 302); } exit(); } // Redirect to external URLS redirect('http://www.google.com/', false); // Redirect with relative URL'S (or a file) redirect('/my-folder/demo.php');
🌐
Hibbard
hibbard.eu › php-headerlocation-not-working-in-mamp
PHP – header('Location: ...') not working in MAMP · James Hibbard
January 11, 2013 - For those having redirect problems after editing the php.ini file inside the MAMP/conf/(your php version) folder, there’s another php.ini file located at MAMP/bin/php/, I also edited that one and the header(Location… problem was solved. ... That other php.ini solution saved my life. thanks a lot for finding that and sharing it with us. ... Thanks for posting this ace solution. Saved me, and I’m sure many others who haven’t posted, hours of frustration and sanity. ... You’re welcome, Jeffrey. Thanks for taking the time to let me know that this worked for you.
🌐
Perishable Press
perishablepress.com › php-redirect-subdirectory-url-to-parent-directory
Redirect any Subordinate URL to its Parent Directory via PHP | Perishable Press
January 7, 2025 - As many of you know, redirecting targeted content down the directory structure can be just as challenging — unless you have the proper tools. So, for the ever-learning developer in you, here is another essential redirect tool for your utility belt: <?php // Permanent 301 Redirect via PHP header("HTTP/1.1 301 Moved Permanently"); header("Location: http://domain.tld/"); exit(); ?>