IIS 重写模块排除机器人但允许 GoogleBot

问题描述 投票:0回答:1

我正在使用以下 IIS 重写规则来阻止尽可能多的机器人。

<rule name="BotBlock" stopProcessing="true">
  <match url=".*" />
  <conditions>
    <add input="{HTTP_USER_AGENT}" pattern="^$|bot|crawl|spider" />
  </conditions>
  <action type="CustomResponse" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" />
</rule>

此规则将阻止所有带有空用户代理字符串或包含

bot
crawl
spider
的用户代理字符串的请求。这很好用,但它也会阻止
googlebot
,这是我不想要的。

那么我如何从上述模式中排除

googlebot
字符串,以便它确实到达网站。

我已经尝试过了

^$|!googlebot|bot|crawl|spider

^$|(?!googlebot)|bot|crawl|spider

^(?!googlebot)$|bot|crawl|spider

^$|(!googlebot)|bot|crawl|spider

但是他们要么阻止所有用户代理,要么仍然不允许 googlebot。谁有解决方案并且了解一些正则表达式?

asp.net regex iis url-rewriting url-rewrite-module
1个回答
0
投票

尝试这个正则表达式

^$|(?!.*googlebot)(bot|crawl|spider)

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.