This is a .php script that may help prevent Google Duplicatate site ppenalization in case you need to run two same sites at same time (for backup purpose for example).


This script is NOT made to work stand alone, it works when its called from other files.
I made it for the purpose to host my primary/original site backup on different domain paralelly with my primary site. But to prevent Google duplicate penalization, this script will reside in backup site folder and when backup webpage is called, it will veriffy if original/main site is up (contains defined phrasse), if up, it will just redirect backup page to original page. If down, it will not redirect, but show backup webpage content.
To make it working with your backup site,

Add line: require("redir.php");
after line: <?php
in your backup site files

script is not tested for the case when site redirecting HTTP to HTTPs

Replace "newextension" by ".php" and "commonextension" by ".html" in case your original site URLs ends by .html and your mirror files ends in .php (because this redir.php script will work in them only if they have .php extension) If original and mirror/backup both have .php extension, try using .php for both mentioned variables
Then also replace following three variables


function get_content($URL){
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_URL, $URL);
      $data = curl_exec($ch);
      return $data;
if (strpos(get_content('http://' . $domain), $keywordtolookfor) !== FALSE)
 $fname=str_replace("newextension", "commonextension", basename($_SERVER['PHP_SELF']));
 header("Location: http://$domain/" . $fname);
 echo "This page is a backup, but the original is alive, so please lets visit original: <a href=\"http://$domain/" . $fname . "\" rel=\"nofollow\">http://$domain/" . $fname . "</a><br />";
 echo 'Original post was not found, this is mirror. If you want to ressurect original site ' . $domain . ',  please download <a title="Contact cPanel hosting provider and ask them to restore this backup for you purchasing '. $domain .' domain." href="'. $pathtopublicbackup .'" rel="nofollow" target="_blank">this cPanel backup</a>.';