网站robots协议介绍及文件写法举例

robots协议是搜索引擎在爬取网站的时候要查看的第一个文件,文件会告诉蜘蛛程序在服务器上什么文件是能够被查看的,对应的不容许查看的内容,蜘蛛程序是不会查看.html

 "robots.txt"文件包含一条或更多的记录,这些记录经过空行分开(以CR,CR/NL, or NL做为结束符),每一条记录的格式以下所示:web

1
"<field>:<optional space><value><optional space>"

在该文件中可使用#进行注解,具体使用方法和UNIX中的惯例同样。该文件中的记录一般以一行或多行User-agent开始,后面加上若干Disallow和Allow行,详细状况以下:服务器

User-agent:网络

   该项的值用于描述搜索引擎robot的名字。在"robots.txt"文件中,若是有多条User-agent记录说明有多个robot会受 到"robots.txt"的限制,对该文件来讲,至少要有一条User-agent记录。若是该项的值设为*,则对任何robot均有效, 在"robots.txt"文件中,"User-agent:*"这样的记录只能有一条。若是在"robots.txt"文件中,加入"User- agent:SomeBot"和若干Disallow、Allow行,那么名为"SomeBot"只受到"User-agent:SomeBot"后面的 Disallow和Allow行的限制。ide

Disallow:网站

   该项的值用于描述不但愿被访问的一组URL,这个值能够是一条完整的路径,也能够是路径的非空前缀,以Disallow项的值开头的URL不会被 robot访问。例如"Disallow:/help"禁止robot访问/help.html、/helpabc.html、/help /index.html,而"Disallow:/help/"则容许robot访问/help.html、/helpabc.html,不能访问 /help/index.html。"Disallow:"说明容许robot访问该网站的全部url,在"/robots.txt"文件中,至少要有一 条Disallow记录。若是"/robots.txt"不存在或者为空文件,则对于全部的搜索引擎robot,该网站都是开放的。搜索引擎

Allow:url

   该项的值用于描述但愿被访问的一组URL,与Disallow项类似,这个值能够是一条完整的路径,也能够是路径的前缀,以Allow项的值开头的URL 是��许robot访问的。例如"Allow:/hibaidu"容许robot访问/hibaidu.htm、/hibaiducom.html、 /hibaidu/com.html。一个网站的全部URL默认是Allow的,因此Allow一般与Disallow搭配使用,实现容许访问一部分网页 同时禁止访问其它全部URL的功能。spa

使用"*"and"$":code

Baiduspider支持使用通配符"*"和"$"来模糊匹配url。

"$" 匹配行结束符。

"*" 匹配0或多个任意字符。


robots文件举例:

1.禁止全部搜索引擎访问网站的任何部分 :

User-agent: *

Disallow: /

2.容许全部的robot访问:

User-agent: *

Disallow: 或者

User-agent: *

Allow: /

3.仅禁止Baiduspider访问您的网站:

User-agent: Baiduspider

Disallow: /

仅容许Baiduspider访问您的网站:

User-agent: Baiduspider

Disallow:

User-agent: *

Disallow: /

4.禁止spider访问特定目录:(须要注意的是对每个目录必须分开声明,而不能写成

"Disallow: /cgi-bin/ /tmp/")

User-agent: *

Disallow: /cgi-bin/

Disallow: /tmp/

Disallow: /~joe/

5.容许访问特定目录中的部分url:

User-agent: *

Allow: /cgi-bin/see

Allow: /tmp/hi

Allow: /~joe/look

Disallow: /cgi-bin/

Disallow: /tmp/

Disallow: /~joe/

6.使用"*"限制访问url:

User-agent: *

Disallow: /cgi-bin/*.htm

7.使用"$"限制访问url:

User-agent: *

Allow: .htm$

Disallow: /

8.禁止访问网站中全部的动态页面:

User-agent: *

Disallow: /*?*

9.禁止Baiduspider抓取网站上全部图片:(如果某一张图片,就是指到对应的图片路径和名称便可)

User-agent: Baiduspider

Disallow: .jpg$

Disallow: .jpeg$

Disallow: .gif$

Disallow: .png$

Disallow: .bmp$

10.仅容许Baiduspider抓取网页和.gif格式图片:

User-agent: Baiduspider

Allow: .gif$

Disallow: .jpg$

Disallow: .jpeg$

Disallow: .png$

Disallow: .bmp$

11.仅禁止Baiduspider抓取.jpg格式图片:

User-agent: Baiduspider

Disallow:


相关文章
相关标签/搜索