写该根目录下面 的robots
robots.txt必须放置在一个站点的根目录下,而且文件名必须全部小写。robots.txt文件的格式
User-agent: 定义搜索引擎的类型
Disallow: 定义禁止搜索引擎收录的地址
Allow: 定义允许搜索引擎收录的地址
我们常用的搜索引擎类型有:
google蜘蛛:googlebot
百度蜘蛛:baiduspider
yahoo蜘蛛:slurp
alexa蜘蛛:ia_archiver
msn蜘蛛:msnbot
altavista蜘蛛:scooter
lycos蜘蛛:lycos_spider_(t-rex)
alltheweb蜘蛛:fast-webcrawler
inktomi蜘蛛: slurp
robots.txt文件的写法 User-agent: * 这里的*代表的所有的搜索引擎种类,*是一个通配符
Disallow: /admin/ 这里定义是禁止爬寻admin目录下面的目录
Disallow: /require/ 这里定义是禁止爬寻require目录下面的目录
Disallow: /ABC/ 这里定义是禁止爬寻ABC整个目录
Disallow: /cgi-bin/*.htm 禁止访问/cgi-bin/目录下的所有以".htm"为后缀的URL(包含子目录)。
Disallow: /*?* 禁止访问网站中所有的动态页面
Disallow: /jpg$ 禁止抓取网页所有的.jpg格式的图片
Disallow:/ab/adc.html 禁止爬去ab文件夹下面的adc.html文件。
User-agent: * 这里的*代表的所有的搜索引擎种类,*是一个通配符
Allow: /cgi-bin/ 这里定义是允许爬寻cgi-bin目录下面的目录
Allow: /tmp 这里定义是允许爬寻tmp的整个目录
Allow: .htm$ 仅允许访问以".htm"为后缀的URL。
Allow: .gif$ 允许抓取网页和gif格式图片robots.txt文件用法举例
例1. 禁止所有搜索引擎访问网站的任何部分
User-agent: *
Disallow: /
实例分析:淘宝网的 Robots.txt文件
User-agent: Baiduspider
Disallow: /
很显然淘宝不允许百度的机器人访问其网站下其所有的目录。
例2. 允许所有的robot访问 (或者也可以建一个空文件 “/robots.txt” file)
User-agent: *
Allow:
例3. 禁止某个搜索引擎的访问
User-agent: BadBot
Disallow: /
例4. 允许某个搜索引擎的访问
User-agent: baiduspider
allow:/
例5.一个简单例子
在这个例子中,该网站有三个目录对搜索引擎的访问做了限制,即搜索引擎不会访问这三个目录。
需要注意的是对每一个目录必须分开声明,而不要写成 “Disallow: /cgi-bin/ /tmp/”。
User-agent:后的*具有特殊的含义,代表“any robot”,所以在该文件中不能有“Disallow: /tmp/*” or “Disallow:*.gif”这样的记录出现。
User-agent: *
Disallow: /cgi-bin/
Disallow: /tmp/
Disallow: /~joe/
Robot特殊参数:
允许 Googlebot:
如果您要拦截除 Googlebot 以外的所有漫游器不能访问您的网页,可以使用下列语法:
User-agent:
Disallow:/
User-agent:Googlebot
Disallow: