首页 > 解决方案 > Apache - htaccess 如何阻止 GET 请求 URL?

问题描述

我想阻止对 URL 的所有访问,例如:

/services/login.php?action=clientlogin&user=K8YcWKOZ&password=UzTXhhn5
/services/login.php?action=clientlogin&user=m4eQ97We&password=xxAz6I8Z

基本上我想给所有包含 403 ERROR 的 URL action:&user&password

我已经测试过:

RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\ /services/login.php\?action=clientlogin&user=([^\s&]+)
RewriteRule .* - [F]

RewriteEngine On
RewriteCond %{QUERY_STRING} ^.*(user|password).* [NC]
RewriteRule ^(.*)$ - [F]

和:

RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\ /services/login.php\?action=clientlogin&user=([^\s&]+)
RewriteRule .* - [F,L]

RewriteCond %{QUERY_STRING} ^.*(user|password).* [NC]
RewriteRule ^(.*)$ - [F,L]

但它无法阻止访问。

如何阻止通过 htaccess 文件访问此 URL?

标签: apache.htaccess

解决方案


你可以试试这个规则:

RewriteEngine On

RewriteCond %{THE_REQUEST} \?action=[^&\s]*&user=[^\s&]*&password=[^&\s]* [NC]
RewriteRule .* - [F,L]

推荐阅读