我想在包含特定字词时阻止POST请求。
我可以使用htaccess文件或CSF防火墙来实现吗?
在两种情况下,我都不知道如何访问POST请求内容以阻止它!
当您谈论发布请求时,您必须指定用于存储字符串的查询,例如index.php?myquery=word1
<= word1是发布请求,或者我们将其称为查询字符串
不要忘记将myquery=
更改为您的
# Block Specific Queries
<IfModule mod_rewrite.c>
RewriteEngine On
#These lines Blocks word1
RewriteCond %{QUERY_STRING} \myquery=word1\b [NC]
RewriteRule ^ - [F]
#These lines Blocks word2
RewriteCond %{QUERY_STRING} \myquery=word2\b [NC]
RewriteRule ^ - [F]
</IfModule>
您需要将此代码添加到接收邮寄请求的页面中(您可以检查标签;其中/path/to/submitpage.php
是在顶部添加此代码的页面:
$action="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
if (strstr($action, 'word1') OR strstr($action, 'word2') OR strstr($action, 'word3'))
{
//Return 404 for these
header('HTTP/1.1 404 Not Found');
//Redirect to specific location
header('Location: https://example.com');
exit;
}
//... The rest of your page code below
?>