Blogger Information
Blog 40
fans 0
comment 1
visits 34261
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
robots.txt文件用法(针对搜索引擎收录的措施)
景云
Original
2952 people have browsed it

1. robots.txt文件存在的目的:

不希望网站的某些页面被抓取和收录

nofollow标签也不能保证页面一定不被搜索引擎收录


2.robots.txt 文件是什么?

robots.txt 即蜘蛛协议,全称为“网络爬虫排除标准”(Robots Exclusion Protocol),也称为爬虫协议、机器人协议等,其作用是告知搜索引擎允许或不允许抓取哪些页面。
搜索引擎蜘蛛在访问网站时会先查看网站根目录下是否存在一个名为 robots.txt 的纯文本文件,robots.txt 用于指定搜索引擎禁止抓取网站某些内容或指定允许抓取某些内容。
robots文件不存在或者是空文件都意味着允许搜索引擎抓取所有内容。

建议即使允许抓取所有内容,也要建一个空的 robots.txt 文件放在根目录下。


3. robots 文件的用法

robots.txt 文件由记录组成,记录之间以空行分开,我们举例说明 robots.txt 的具体格式。

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

  1. User-agent: *
  2. Disallow: /

3.2 允许所有搜索引擎蜘蛛访问:

  1. User-agent: *
  2. Allow: /
  3. //或者建一个空文件“robots.txt”

3.3 禁止某个搜索引擎访问:

  1. User-agent: Baiduspider
  2. Disallow: /
  3. //Baiduspider:百度搜索引擎

3.4 允许某个搜索引擎访问:

  1. User-agent: Baiduspider
  2. Allow: /
  3. //Baiduspider:百度搜索引擎

3.5 只允许某个搜索引擎访问,其他搜索引擎禁止访问:

  1. User-agent: Baiduspider
  2. Disallow:
  3. User-agent: *
  4. Disallow: /

3.6 只禁止某个搜索引擎访问,其他搜索引擎允许访问:

  1. User-agent: Baiduspider
  2. Disallow: /
  3. User-agent: *
  4. Disallow:

4. 书写 robots 文件时需要注意以下细节:

  • 一定不要写绝对路径,就是不要带网站域名,用/代替即可。
  • 注意 robots 文件中的所有符号都是在英文状态下写的,比如 Disallow: /admin/ 中的:是英文状态下的。
  • 注意空格,例如 Disallow: /admin/ 中:后面紧跟着一个空格。
  • 注意大小写,例如 Disallow: /admin/ 中 Disallow 的D是大写的。
  • robots 是有生效时间的,是由百度决定的,几天或者两个月以内,所以一定不要随便屏蔽整站。
  • 还有一点要弄清楚,Disallow: /help 的意思是禁止蜘蛛访问 /help.html、/helpabc.html、/help/index.html 等所有带 help 的文件及文件夹;Disallow:/help/ 则是禁止蜘蛛访问 /help/index.html 这种形式的路径,允许访问 /help.html、/helpabc.html。

5. robots.txt 文件内容释义:

User-agent

  1. User-agent 代表蜘蛛名称,例如:
  2. User-agent:Baiduspider 代表针对百度蜘蛛。
  3. User-agent:* 代表所有的搜索引擎种类,*是一个通配符。

Disallow

  1. Disallow 表示不允许,代表禁止蜘蛛爬取的文件或目录。例如:
  2. Disallow: /admin/ 代表禁止爬取 admin 目录下的所有文件。
  3. Disallow: /cgi-bin/*.htm 代表禁止访问 /cgi-bin/ 目录下的所有以.htm为后缀的 URL(包含子目录)。
  4. Disallow: /*?* 代表禁止访问网站中所有包含问号?的网址。
  5. Disallow: /.jpg$ 代表禁止爬取网页所有的.jpg格式的图片。
  6. Disallow:/ad/ct.html 代表禁止爬取 ad 文件夹下的 ct.html 文件。

Allow

  1. Allow 表示允许,代表允许蜘蛛爬取的目录或文件。例如:
  2. Allow: /cgi-bin/ 代表允许爬取 cgi-bin 目录下的目录。
  3. Allow: /tmp 代表允许爬取 tmp 的整个目录。
  4. Allow: .htm$ 代表仅允许访问以.htm为后缀的 URL
  5. Allow: .gif$ 允许爬取网页和 GIF 格式的图片。

Sitemap

  1. Sitemap 一般放在 robots.txt 内容最底部,用于告知网络爬虫这个页面是网站地图,如 Sitemap:http://www.youdomainname.com/sitemap.htm。

附:

主流搜索引擎都遵守 robots 文件指令,robots.txt 禁止爬取的文件搜索引擎将不访问、不爬取。但要注意的是,被 robots 文件禁止爬取的 URL 还是可能出现在搜索结果中。只要有导入链接指向这个 URL,搜索引擎就知道这个 URL 的存在。虽然不会抓取页面内容,但是可能以下面几种形式显示在搜索结果中:
只显示 URL,没有标题、描述,谷歌常这样处理。
显示开放目录或雅虎等重要目录收录的标题和描述。
导入链接的锚文字显示为标题和描述,百度常这样处理。

要想使 URL 完全不出现在搜索结果中,需要使用页面上的 meta robots 标签。

转自:robots.txt文件用法完全攻略

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!