Saturday, January 29, 2022

redirecting specific php pages

I used the technique mentioned at this page and edited some of our php/html files to automatically redirect to our new domain with the same request URI, by adding a line
require("redirector.php");

with redirector.php having the following:

<?php
$domain = $_SERVER["SERVER_NAME"];
$requri = $_SERVER["REQUEST_URI"];
$newlocation = "location: https://our.new.domain" . $requri;
if ($domain == "www.olddomain.org" || $domain == "olddomain.org" )  { 
   Header( "HTTP/1.1 301 Moved Permanently" ); 
   header($newlocation); 
}
?>

Those php pages which have html content should have the above "require" line right at the top, before the html or head tags.

In the html file, put in a javascript redirect instead.

if (loc.indexOf('https://www.olddomain.org')==0){
    window.location.href = loc.replace('https://www.olddomain.org','https://our.new.domain);
}
if (loc.indexOf('https://olddomain.org')==0){
    window.location.href = loc.replace('https://olddomain.org','https://our.new.domain');
}


No comments:

Post a Comment