Robots.txt (也称为爬虫协议、爬虫规则、机器人协议 等)是存放在站点根目录下的一个纯文本文件。虽然它的设置很简单,但是作用却很强大。它可以指定搜索引擎蜘蛛只抓取指定的内容,或者是禁止搜索引擎蜘蛛抓取网站的部分或全部内容。
自动生成方式:
站长工具 > robots文件生成:http://tool.chinaz.com/robots/
使用方法:
robots.txt 文件应该放在网站根目录下,并且该文件是可以通过互联网进行访问的。
例如:如果您的网站地址是 http://www.yourdomain.com/ 那么,该文件必须能够通过 http://www.yourdomain.com/robots.txt 打开并看到里面的内容。
格式:
User-agent:
用于描述搜索引擎蜘蛛的名字,在" Robots.txt "文件中,如果有多条User-agent记录说明有多个搜索引擎蜘蛛会受到该协议的限制,对该文件来说,至少要有一条User-agent记录。如果该项的值设为*,则该协议对任何搜索引擎蜘蛛均有效,在" Robots.txt "文件中,"User-agent:*"这样的记录只能有一条。
Disallow:
用于描述不希望被访问到的一个URL,这个URL可以是一条完整的路径,也可以是部分的,任何以Disallow开头的URL均不会被Robot访问到。
robots.txt 样例代码:
例1. 禁止所有搜索引擎访问网站的任何部分
User-agent:
Disallow: /
例2. 允许所有的搜索引擎访问网站的任何部分
User-agent:
Disallow:
例3. 仅禁止Baiduspider访问您的网站
User-agent: Baiduspider
Disallow: /
例4. 仅允许Baiduspider访问您的网站
User-agent: Baiduspider
Disallow:
例5. 禁止spider访问特定目录
User-agent: *
Disallow: /cgi-bin/
Disallow: /tmp/
Disallow: /data/
注意事项:
- 三个目录要分别写。
- 请注意最后要带斜杠。
- 带斜杠与不带斜杠的区别。
例6. 允许访问特定目录中的部分url
实现a目录下只有b.htm允许访问
User-agent: *
Allow: /a/b.htm
Disallow: /a/
例7、仅允许国内搜素引擎和谷歌爬取
User-agent: Baiduspider
Disallow:
User-agent: Sosospider
Disallow:
User-agent: sogou spider
Disallow:
User-agent: YodaoBot
Disallow:
User-agent: YodaoBot
Disallow:
User-agent: Googlebot
Disallow:
User-agent: *
Disallow: /