1

我试图通过在“.htaccess”文件中阻止它们来过滤一些机器人,如下所示:

#UniversalRules
SetEnvIfNoCase User-Agent ^$ bad_bot #leave this for blank user-agents
SetEnvIfNoCase User-Agent .*\@.* bad_bot
SetEnvIfNoCase User-Agent .*bot.* bad_bot

但是这些规则也阻止了好的机器人,所以我在下面添加

#Goodbots
SetEnvIfNoCase User-Agent .*google.* good_bot
SetEnvIfNoCase User-Agent .*bingbot.* good_bot #bing

最后是阻塞规则

Order Allow,Deny
Allow from all
Deny from env=bad_bot

但是当我使用 GoogleBot useragent (Googlebot/2.​​1 (+ http://www.googlebot.com/bot.html ) 我得到 - 403 被禁止。

怎么了 ?

4

1 回答 1

1

GoogleBot设置了两个环境变量;设置变量 ( good_bot) 不会取消设置其他变量 ( bad_bot)。您可以设置一个变量,然后再取消设置:

#UniversalRules
SetEnvIfNoCase User-Agent ^$           bad_bot
SetEnvIfNoCase User-Agent .*\@.*       bad_bot
SetEnvIfNoCase User-Agent .*bot.*      bad_bot
#Goodbots
SetEnvIfNoCase User-Agent .*google.*  !bad_bot
SetEnvIfNoCase User-Agent .*bingbot.* !bad_bot

有关示例,请参见mod_setenvif参考。BrowserMatchNoCase以更短的语法提供相同的功能。你可以删除.*你的正则表达式中的所有内容。

于 2018-01-06T20:29:18.023 回答