This solution requires the shell_exec php function
List all deleted URIs in a file called gone_urls.txt
replace the index.php file with the following content
<?php
$url = "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
$escaped_url = "https:".htmlspecialchars( $url, ENT_QUOTES, 'UTF-8' );
$command='grep -Fxn "'.$escaped_url.'" '.__DIR__ . '/gone_urls.txt';
$out=shell_exec($command);
if($out){
header("HTTP/1.1 200 OK");
?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Sorry, this page is gone forever and ever</title>
<meta name="robots" content="noindex">
</head>
<body>
<h1>Sorry, this page is gone forever and ever</h1>
</body>
</html>
<?php
die();
}
/**
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* @package WordPress
*/
/**
* Tells WordPress to load the WordPress theme and output it.
*
* @var bool
*/
define( 'WP_USE_THEMES', true );
/** Loads the WordPress Environment and Template */
require __DIR__ . '/wp-blog-header.php';