Robots.txt 中的多个用户代理 [英] Multiple User Agents in Robots.txt

查看:40
本文介绍了Robots.txt 中的多个用户代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 robots.txt 文件中,我有以下部分

用户代理:Bot1禁止:/A用户代理:Bot2禁止:/B用户代理: *禁止:/C

将语句 Disallow:c 对 Bot1 可见机器人2?

解决方案

tl;dr: 不,Bot1 和 Bot2 会很乐意抓取以 C 开头的路径.

每个机器人最多只遵守一条记录(块).

原始规格

原始规范中说:

<块引用>

如果值为*",则该记录描述未与任何其他记录匹配的任何机器人的默认访问策略.

已过期的 RFC 草案

原始规范,包括一些新增内容(如 Allow)成为 RFC 的草案,但从未被接受/发布.在 3.2.1 The User-agent line 中,它说:

<块引用>

机器人必须遵守/robots.txt 中包含 User-Agent 行的第一条记录,该行的值包含机器人的名称标记作为子字符串.名称比较不区分大小写.如果不存在这样的记录,它应该遵循带有*"值的 User-agent 行的第一个记录(如果存在).如果没有记录满足任一条件,或者根本没有记录,则访问不受限制.

因此它确认了对原始规范的解释.

实施

例如 Google,举了一个例子 似乎遵循规范:

<块引用>

robots.txt 文件中的每个部分都是独立的,不是建立在前面的部分之上的.例如:

用户代理:*禁止:/folder1/用户代理:Googlebot禁止:/folder2/

在本例中,只有与 /folder2/ 匹配的网址才会被 Googlebot 禁止.

In robots.txt file I have following sections

User-Agent: Bot1
Disallow: /A

User-Agent: Bot2
Disallow: /B

User-Agent: *
Disallow: /C

Will statement Disallow:c be visible to Bot1 & Bot2 ?

解决方案

tl;dr: No, Bot1 and Bot2 will happily crawl paths starting with C.

Each bot only ever complies to at most a single record (block).

Original spec

In the original specification it says:

If the value is '*', the record describes the default access policy for any robot that has not matched any of the other records.

Expired RFC draft

The original spec, including some additions (like Allow) became a draft for RFC, but never got accepted/published. In 3.2.1 The User-agent line it says:

The robot must obey the first record in /robots.txt that contains a User-Agent line whose value contains the name token of the robot as a substring. The name comparisons are case-insensitive. If no such record exists, it should obey the first record with a User-agent line with a "*" value, if present. If no record satisfied either condition, or no records are present at all, access is unlimited.

So it confirms the interpretation of the original spec.

Implementations

Google, for example, gives an example that seems to follow the spec:

Each section in the robots.txt file is separate and does not build upon previous sections. For example:

User-agent: *
Disallow: /folder1/

User-Agent: Googlebot
Disallow: /folder2/

In this example only the URLs matching /folder2/ would be disallowed for Googlebot.

这篇关于Robots.txt 中的多个用户代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆