互联网 patron No comments

用.htaccess文件屏蔽恶意User Agent

屏蔽单个恶意User Agent

1
2
3
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} UserAgentName [NC]
RewriteRule .* - [F,L]

屏蔽多个恶意User Agent

1
2
3
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^.*(UserAgentName1|UserAgentName2).*$ [NC]
RewriteRule .* - [F,L]

屏蔽名字为空的User Agent

1
2
3
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^-?$
RewriteRule ^ - [F]
0