ITPub博客

首页 > 云计算 > 虚拟化 > Apache 使用 .htaccess屏蔽恶意 User Agent

Apache 使用 .htaccess屏蔽恶意 User Agent

虚拟化 作者:126云 时间:2021-04-12 15:11:04 0 删除 编辑

使用 .htaccess 屏蔽 User Agent 的方法很多,这里使用 rewrite 规则把这些 User Agent 转移走,以达到屏蔽的效果。

代码如下
RewriteCond %{HTTP_USER_AGENT} “.*EmbeddedWB.*” [OR]
RewriteCond %{HTTP_USER_AGENT} “.*QunarBot.*” [OR]
RewriteCond %{HTTP_USER_AGENT} “.*Windows 98.*” [OR]
RewriteCond %{HTTP_USER_AGENT} “^Mozilla/4.0$”
RewriteRule ^(.*)$ http://cao.ni.ma/

使用 .htaccess 需要了解一些正则表达式语法,以正确匹配字符串。

如果你觉得有用,屏蔽恶意 User Agent前,不妨先分析一下自己的网站日志,根据自己的需要定制。可以使用 Firefox+User Agent Switcher 测试效果,Chrome 也有类似的切换 User Agent 的扩展程序。



来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69957453/viewspace-2767591/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
文章来自网络,如有侵害,请私信

注册时间:2019-12-14

  • 博文量
    344
  • 访问量
    257050