设为首页
收藏本站
最新电影
> 子栏目 业界动态 | 网站优化SEO | 网站策划
您现在的位置: 首页=>运营资讯=>网站优化SEO 订阅本栏目  
robots 书写实例讲解
时间: 2009-06-29 16:58:15 阅读次数:2900


什么是robots.txt文件?
搜索引擎使用spider程序自动访问互联网上的网页并获取网页信息飞飞Asp技术乐~园spider在访问一个网站时,会首先会检查该网站的根域下是否有一个叫做robots.txt的纯文本文件,这个文件用于指定spider在您网站上的抓取范围飞飞As@p技术乐园您可以在您的网站中创建一个robots.txt,在文件中声明该网站中不想被搜索引擎收录的部分或者指定搜索引擎只收录特定的部分

请注意,仅当您的网站包含不希望被搜索引擎收录的内容时,才需要使用robots.txt文件如果您希望搜索引擎收录网站上所有内容,请勿建立robots.txt文件

———

robots.txt文件放在哪里?

robots.txt文件应该放置在网站根目录下
举例来说,当spider访问一个网站(比如
http://www.abc.com飞飞~Asp技术乐园)时,首先会检查该网站中是否存在http://www.abc.com/robots.txt这个文件,如果Spider找到这个文件,它就会根据这个文件的内容,来确定它访问权限的范围
(robots.txt只能存放于网站的根目录下,每个网站,或每个域名(包括子域名),只能有一个robots.txt

———

如果您的网站在被百度收录之后才设置Robots文件禁止抓取,那么新的Robots文件通常会在48小时内生效,生效以后的新网页,将不再建入索引需要注意的是,robots.txt禁止收录以前百度已收录的内容,从搜索结果中去除可能需要数月的时间(百度官方说明...)

———

robots.txt 允许与禁止蜘蛛的写法

#禁止所有蜘蛛爬任何目录
User-agent: *
Disallow: /

#允许所有蜘蛛爬任何目录
User-agent: *
Disallow:

#允许百度蜘蛛爬,禁止其他蜘蛛爬任何目录
User-agent: baiduspider
Disallow:

User-agent: *
Disallow: /

———

robots.txt中的文件与目录

错误写法:

User-agent: *
Disallow: /dir1/ /dir2/ /dir3/

正确写法:

User-agent: *
Disallow: /dir1/
Disallow: /dir2/
Disallow: /dir3/
Disallow: /help.html

不允许所有搜索引擎蜘蛛爬dir1、dir2、dir3这三个目录及help.html这个文件!
特别注意的是,不要省略掉目录名后的“/”,不然,Spider便极有可能误读相应的设置

———

robots.txt中限定项的顺序

错误写法:

User-agent: *
Disallow: /
User-agent: Googlebot
Disallow:

该设定本意是想允许Google访问所有页面,同时禁止其他Spider的访问但在这样的设置下,Googlebot在读取前2行后便会离开网站,后面对其的“解禁”完全失去了意义

正确写法:

User-agent: Googlebot
Disallow:
User-agent: *
Disallow: /

———

robots.txt 复杂较多的情况下该如何注释哪?

错误写法:

User-agent: Googlebot #这是对Google的设置
Disallow:

正确写法:

#这是对Google的设置
User-agent: Googlebot
Disallow:

———

下表是权威,百度官方对外资料!

robots.txt文件用法举例

例1. 禁止所有搜索引擎访问网站的任何部分 User-agent: *
Disallow: /

例2. 允许所有的robot访问
(或者也可以建一个空文件 "/robots.txt")

User-agent: *
Disallow:
或者
User-agent: *
Allow: /
例3. 仅禁止Baiduspider访问您的网站 User-agent: Baiduspider
Disallow: /
例4. 仅允许Baiduspider访问您的网站 User-agent: Baiduspider
Disallow:

User-agent: *
Disallow: /
例5. 禁止spider访问特定目录
  在这个例子中,该网站有三个目录对搜索引擎的访问做了限制,即robot不会访问这三个目录需要注意的是对每一个目录必须分开声明,而不能写成 "Disallow: /cgi-bin/ /tmp/"
User-agent: *
Disallow: /cgi-bin/
Disallow: /tmp/
Disallow: /~joe/
例6. 允许访问特定目录中的部分url User-agent: *
Allow: /cgi-bin/see
Allow: /tmp/hi
Allow: /~joe/look
Disallow: /cgi-bin/
Disallow: /tmp/
Disallow: /~joe/
例7. 使用"*"限制访问url
   禁止访问/cgi-bin/目录下的所有以".htm"为后缀的URL(包含子目录)
User-agent: *
Disallow: /cgi-bin/*.htm
例8. 使用"$"限制访问url
   仅允许访问以".htm"为后缀的URL
User-agent: *
Allow: .htm$
Disallow: /
例9. 禁止访问网站中所有的动态页面 User-agent: *
Disallow: /*?*
例10. 禁止Baiduspider抓取网站上所有图片
   仅允许抓取网页,禁止抓取任何图片
User-agent: Baiduspider
Disallow: .jpg$
Disallow: .jpeg$
Disallow: .gif$
Disallow: .png$
Disallow: .bmp$
例11. 仅允许Baiduspider抓取网页和.gif格式图片
   允许抓取网页和gif格式图片,不允许抓取其他格式图片
User-agent: Baiduspider
Allow: .gif$
Disallow: .jpg$
Disallow: .jpeg$
Disallow: .png$
Disallow: .bmp$
例12. 仅禁止Baiduspider抓取.jpg格式图片 User-agent: Baiduspider
Disallow: .jpg$

robots.txt文件参考资料


robots.txt文件的更具体设置,请参看以下链接:


· Web Server Administrator's Guide to the Robots Exclusion Protocol
·
HTML Author's Guide to the Robots Exclusion Protocol
·
The original 1994 protocol description, as currently deployed
· The revised Internet-Draft specification, which is not yet completed or implemented




站内搜索    

下一篇提高Google Adsense的eCPM的常用技巧

上一篇Google 百度 搜索引擎习惯的分析

本栏目最新 栏目最新列表
增加网站外链的快速方法
网站上线前必做的30个检查
新的友情链接参考标准(没有google的PR情况
优化Google的AdSense广告的五个工具
王通讲SEO八大基础
网站优化策划 栏目最新列表
增加网站外链的快速方法
网站上线前必做的30个检查
新的友情链接参考标准(没有google的PR情况
优化Google的AdSense广告的五个工具
王通讲SEO八大基础
站点最新 站点最新列表
微博推广的一些技巧
xhEditor v1.1.7 发布,
收集的一些轻量级非常实
50个新鲜兼容最新版本的
javascript中cookie的设
Excel中出现#VALUE!、#D
jquery插件:飞飞表情插件
十个使用HTML5开发的精彩
支持HTML5的浏览器有哪些
飞妮莫属:漫画:如何写出
历史最热10条信息  
AWStats安装QQ传真IP插件
MIME介绍 及 [1] [2] [3]
巧用Google和迅雷来下载
Transact SQL 常 [1] [2]
VIA Rhine II Fast Ethe
电脑常用端 [1] [2] [3]
Do you get a kick out
十道羊皮卷 欣赏+mp3版+
每日一句:A friend and
经典__悟透JavaScript
 width= 
伟哥博客 西安房产 123最新电影 三四六四