$best_percent) { $best_percent = $percent; $redirect_target = $data[1]; } } // close the file fclose($handle); } // if the best match was better than a 99% match if($best_percent > 99) { // issue a 301 redirect header("HTTP/1.0 301 Moved Permanently"); // if the target URL has a :// send it as a relative redirect // otherwise send it as a fully qualified (external) redirect if ( strpos($redirect_target, '://') !== false) { header("Location: " . $redirect_target); } else { header("Location: http://" . $_SERVER['HTTP_HOST'] . "/" . $redirect_target); } exit(); } // if there was not match in excess of the target % then send a 404 and write in the 404 page HTML header("HTTP/1.0 404 Not Found"); if (($handle = fopen("../index.php", "r")) !== FALSE) { // while there is data to read, get a line while($data = fgets($handle, 1000)) { echo $data; } // close the file fclose($handle); } else { // if the 404 file was not found, output a generice message echo "Error 404, page not found."; } exit(); ?>