使用 .htaccess 阻止 Yandex、百度和 MJ12bot

pat*_*der 4 .htaccess

我厌倦了 Yandex、百度和 MJ12bot 吃掉我所有的带宽。他们甚至都不关心无用的 robots.txt 文件。

我还想阻止任何包含“蜘蛛”一词的用户代理。

我一直在我的 .htaccess 文件中使用以下代码来查看用户代理字符串并以这种方式阻止它们,但似乎它们仍然通过。这段代码正确吗?有没有更好的办法?

BrowserMatchNoCase "baidu" bots
BrowserMatchNoCase "yandex" bots
BrowserMatchNoCase "spider" bots
BrowserMatchNoCase "mj12bot" bots

Order Allow,Deny
Allow from ALL
Deny from env=bots
Run Code Online (Sandbox Code Playgroud)

sta*_*een 6

要阻止用户代理,您可以使用:

SetEnvIfNoCase User-agent (yandex|baidu|foobar) not-allowed=1

 Order Allow,Deny
Allow from ALL
Deny from env=not-allowed
Run Code Online (Sandbox Code Playgroud)