网站的robots.txt文件怎么写

  • A+
所属分类:Web开发

实例(#后面的内容是为方便阅读而设):
# robots.txt file start
# Exclude Files From All Robots:
User-agent: *
Disallow: /security/
Disallow: /admin/
Disallow: /admin
# End robots.txt file
User-agent:用于描述搜索引擎蜘蛛的名字,在 Robots.txt 文件中,如果有多条User-agent记录说明有多个搜索引擎蜘蛛会受到该协议的限制,对该文件来说,至少要有一条User-agent记录。如果该项的值设为*,则该协议对任何搜索引擎蜘蛛均有效,在”Robots.txt 文件中,“User-agent:*”这样的记录只能有一条。
Disallow:就表示不允许蜘蛛访问,你可以根据自己的需要设立后面的目录或者是文件,比如管理员后台登陆的页面或者目录等。
Disallow: /admin/:是指允许搜索引擎蜘蛛抓取/admin.html,而不能抓取/admin/index.html。
Disallow: /admin:是指/admin.html 和/admin/index.html都不允许搜索引擎蜘蛛抓取。
下面有四个举例:
例一:通过”/robots.txt”禁止所有搜索引擎蜘蛛抓取”/bin/cgi/”目录,以及 “/tmp/”目录和 /foo.html 文件,设置方法如下:
User-agent: *
Disallow: /bin/cgi/
Disallow: /tmp/
Disallow: /foo.html
例二:通过”/robots.txt”只允许某个搜索引擎抓取,而禁止其他的搜索引擎抓取。
如:只允许名为”slurp”的搜索引擎蜘蛛抓取,而拒绝其他的搜索引擎蜘蛛抓取 “/cgi/” 目录下的内容,设置方法如下:
User-agent: *
Disallow: /cgi/
User-agent: slurp
Disallow:
例三:禁止任何搜索引擎抓取我的网站,设置方法如下:
User-agent: *
Disallow: /
例四:只禁止某个搜索引擎抓取我的网站
如:只禁止名为“slurp”的搜索引擎蜘蛛抓取,设置方法如下:
User-agent: slurp
Disallow: /
Robots Meta标签
robot.txt主要是针对整个网站而言,相比之下,Robots Meta标签则是针对某个具体的网页不希望被搜索到。
需要注意的是:上述的robots.txt和Robots META标签限制搜索引擎机器人(Robots)抓取站点内容的办法只是一种规则,需要搜索引擎机器人的配合才行,并不是每个Robots都遵守的,这方面百度似乎做得不是很好。

下载服务恢复

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

Blue Captcha Image
Refresh

*