robots.txt文件的格式

添加评论 2010年2月2日

“robots.txt”可以包含一条或多条记录,这些记录通过空行分开,以CR、CR/NL、or NL作为结束符。每条记录的格式如下:

“<field>:<optionalspace><value><optionalspace>”。

robots.txt文件可以用#注解。该文件中的记录通常通过一行或多行User-agent开始,后面加上若干Disallow行。详细情况如下:

user-agent的值用来描述搜索引擎robot的名字。robots.txt文件中如果有多条user-agent记录,说明有多个robot会受到该协议的限制,对该文件来说,至少要有一条user-agent记录。如果该项的值设为*,则该协议对任何机器人有效。在robots.txt文件中“user-agent:*”这样的记录只允许有一条。

disallow的值用于描述不想被搜索引擎访问的一个URL。这个URL可以是一条完整的路径,也可以是路径的一部分。任何以disallow开头的路径都不会被rob0ts访问到。例如:disallow:/help。对于/help.html和/help/index.html都不会被搜索引擎访问。而disallow:/help/。则允许robots访问help.html而不能访问/help/index.html。任何一条disallow记录为空,说明该网站的所有部分都允许被访问。robots.txt文件中至少有一条disallow命令,如果robots.txt文件为空,则该网站对所有搜索引擎都是开放的。

robots.txt的用法举例:

User-agent:*

Disallow:/

禁止所有搜索引擎访问网站的任何部分。

User-agent:*

Disallow:

允许所有robot访问。等同于空robots.txt文件。

User-agent:

BadBot

Disallow:/

禁止某个搜索引擎的访问。

User-agent:

Baiduspider

disallow:

User-agent:*

Disallow:/

允许某个搜索引擎的访问。

User-agent:*

Disallow:

/cgi-bin/

disallow:/tmp/

disallow:/~joe/

一个简单的例子。该例中,该网站有三个目录对搜索引擎做了限制,即搜索引擎不会访问这三个目录。需要注意的是对每个目录要分开说明,而不能写成disallow:/cgi-bin/ /tmp/。

User-agent后面的*有特殊含义,代表“any robot”所以该文件中不能有“disallow:/tmp/*”或“disallow:*.gif”这样的记录出现。

  1. 2010年2月14日 at 21:34 | #1

    Hello! Can you tell me how i can register mail at google google http://google.com

  2. 2010年2月18日 at 20:36 | #2
    admin

    Open the Web: “http://www.gmail.com“, click the register can be.

  3. 2010年3月13日 at 15:29 | #3
    倩舞飞杨

    对于我来说,你举的这几个例子足够用了。

  1. 还没有 trackbacks
订阅评论