How To Redirect Permanently with PHP

Hi,

To do a permanent redirection using PHP, for whatever SEO needs you may have, the code is

<?php
//Standard 404.php file

//Looking for my tnmailserver?
if(strpos($_SERVER[“REQUEST_URI”], “/Projects/TNMailServer-Full.aspx”) !== FALSE)
{
header(“HTTP/1.1 301 Moved Permanently”);
header(“Location: /TNMailServer”);
exit(0);
}
?>

The exit is importantly, especially if you still have other code below this snippet performing other checks, or showing the standard 404 page.

Leave a Reply

Your email address will not be published. Required fields are marked *

*