View Full Version : Redirect

08-15-2008, 05:17 AM

I'd like to ask how to redirect from one PHP to another PHP provided that they are in a different directory. I already found a code that can redirect from one PHP page to another PHP page. However, that is only in the same directly. The code is shown below:

/* Redirect to a different page in the current directory that was requested */
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = 'anotherpage.php';
header("Location: http://$host$uri/$extra");

I'd like to know how to redirect to another page in an upper directory.

----> index.php
----> idliketogohere.php
--> currentpage.php
--> anotherpage.php

Len Whistler
08-15-2008, 05:55 AM
Use the complete URL.

header("Location: http://www.mysite.php/folder/folder/file.php");


08-15-2008, 06:26 AM
I discovered the answer. Here:

$host = $_SERVER['HTTP_HOST'];
$folder = "lotcheckeditor";

header("Location: http://$host/$folder/pages/sorry.html");