RewriteEngine On
RewriteRule ^index-maintenance\.php$ - [L]
RewriteRule .* /index-maintenance.php [L]
字符串 然后,index-maintenance.php文件看起来像是:
<?php
$record = TRUE; // whether or not to record requests
header('HTTP/1.1 503 Service Unavailable', TRUE, 503);
header('Retry-After: 18000');
if($record) {
// Get remote IP
// If the site uses cloudflare, the true remote IP is served
// in the HTTP_CF_CONNECTING_IP server var:
$ip = isset($_SERVER['HTTP_CF_CONNECTING_IP'])
? $_SERVER['HTTP_CF_CONNECTING_IP']
: $_SERVER['REMOTE_ADDR'];
ob_start();
// Request date / IP / URL
echo date('Y-m-d H:i:s: ')
. 'Remote IP: ' . $ip
. ' - ' . $_SERVER['REQUEST_METHOD']
. ' ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']
. "\r\n";
// User agent
echo $_SERVER['HTTP_USER_AGENT'] . "\r\n";
// If you needed all headers:
# foreach(getallheaders() as $header => $value)
# echo "$header: $value\r\n";
// If you wanted raw request data vs. parsed POST data:
# $postdata = file_get_contents('php://input');
# if(strlen($postdata)) echo $postdata."\r\n";
// Post data / Cookies / Files
if(count($_POST) || count($_COOKIE)) {
ob_start();
echo "POST\n";
var_dump($_POST);
echo "COOKIES\n";
var_dump($_COOKIE);
echo "FILES\n";
var_dump($_FILES);
$postdata = ob_get_clean();
echo str_replace("\n","\r\n",$postdata);
}
echo "\r\n";
// usage of random character string discourages guessing
// the url if the directory is web-accessible; but, if at
// all possible, make it inaccessible:
file_put_contents('../requests_n5io09d21mkp.log',ob_get_clean(),FILE_APPEND);
}
// then, a simple maintenance page:
?>
<!DOCTYPE html>
<html>
<head>
<title>Site Under Maintenance</title>
</head>
<style type="text/css">
body {
margin: 0;
width: 100vw;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.notice {
color: #808080;
font: bold 20px/1.6em sans-serif;
text-align: center;
}
</style>
<body>
<p class="notice">
We're sorry. The site is under maintenance.<br/>Please check back later.
</p>
</body>
</html>
1条答案
按热度按时间vwkv1x7d1#
我知道这是个老问题。如果您使用共享主机,正如您所建议的,您可能被限制为必须通过脚本重定向所有流量。
我不得不这么做一次。对于一个被黑客攻击的WordPress网站,我需要确定它是如何被攻击的。就像你说的,我用一个.htaccess文件将所有请求重定向到一个PHP脚本,该脚本将呈现一个简单的“站点正在维护”页面,但也会记录该请求-发布数据,cookie,上传文件名-几乎所有我想观察的东西。
不过,方便的是,该网站也受到Cloudflare的保护;因此,通过这样做,Cloudflare最终在维护页面上看到503不可用,并服务缓存,从而保持站点几乎完全正常运行。更好的是,维护页面仍然能够记录请求。
我的.htaccess文件显示如下:
字符串
然后,
index-maintenance.php
文件看起来像是:型