

对此,很多关注互联网的博客网站都已发文分享,而且官方也有具体说明,我就不继续赘述了。
写这篇文章的目的,只要是为了纠正以前的一个 robots 认知错误!记得张戈博客前段时间分享过一篇《浅谈网站使用七牛云存储之后的 robots.txt 该如何设置?》,我在文章分享的七牛镜像域名的 robots 应该如下设置:

本来当时使用百度 robots 检测也是没问题的:

当这次 robots 工具升级之后,我使用新增的【规则校验】功能试了下,竟然是如下结果:

纳尼?最后的禁封难道不起作用了??于是,我试着把禁止规则移动到最前面看看效果:

结果,依然全部允许抓取!!这不科学啊!
想了半天,我看只有一个解释了,那就是百度只看 Baiduspider 标签了,其他的规则它不理睬!难怪之前百度依然会收录我的七牛静态域名:

好吧,上有政策下有对策,对之前的规则稍作修改即可:
# robots.txt for statice domain User-agent: Baiduspider Allow: /wp-content/uploads/*.jpg$ Allow: /wp-content/uploads/*.png$ Disallow: / User-agent: 360Spider Allow: /wp-content/uploads/*.jpg$ Allow: /wp-content/uploads/*.png$ Disallow: / User-agent: Baiduspider-image Allow: /wp-content/uploads/*.jpg$ Allow: /wp-content/uploads/*.png$ Disallow: / User-agent: 360Spider-Image Allow: /wp-content/uploads/*.jpg$ Allow: /wp-content/uploads/*.png$ Disallow: / User-agent: * Disallow: /
再次检测已经没问题了:

接着,为了验证之前的一个疑问,我进一步测试了下:

从图中的结果可以看出,禁止规则的前后位置,并不影响允许抓取的规则,说明不存在前后优先级!从而推翻了张戈博客旧文章关于前后优先级的说法。而真正的优先级应该是:Allow 高于 Disallow,及【允许规则】高于【禁封规则】。
最后,总结一下。通过本文测试,说明了 2 个问题:
i. 当 robots 中存在百度蜘蛛标签 Baiduspider 时,通用规则将失效!虽然还不知道是不是 robots 升级之后的 bug,为了保险起见,站长在写 robots 的时候,如果存在具体 UA 规则,记得额外加上禁封规则会比较好!
ii. robots 规则并不区分前后优先级,而是 Allow 的优先级大于 Disallow(即[允许规则]>[禁封规则])。
好了,这就是本次百度 robots 工具升级的新发现,希望对你有所帮助!
最新补充:最近测试发现本文所写问题已被百度修复!