最详细的robots文件的写法解析(符合搜索需求)

2020-11-12    分类: 网站建设

做SEO的朋友基本都了解点robots,但是在实际SEO网站优化中robots.txt文件具体应该如何编写恐怕是一堆SEO的困扰,瞎写,乱写robots规则直接影响网站优化的成果。robots.txt文件具体要怎么写?今天创新互联把最详细的robots文件的写法告知大家。
robots.txt是什么

一、robots.txt文件它的作用是什么,为什么要写?


robots.txt是用来告诉搜索引擎网站上哪些内容可以被访问、哪些不能被访问。当搜索引擎访问一个网站的时候,它首先会检查网站是否存在robots.txt,如果有则会根据文件命令访问有权限的文件。
每个网站需要根据自身的要求写好robots.txt文件,robots.txt文件长什么样子?我们可以看看几个网站的robots.txt文件。
淘宝robots.txt文件

淘宝robots.txt文件

百度robots.txt文件

百度robots.txt文件

而一个网站为什么要写robots.txt,主要有四点:

1、保护网站安全

2、节省流量

3、禁止搜索引擎收录部分页面

4、引导蜘蛛爬网站地图

二、robots.txt的写法与步骤

1、定义搜索引擎

用User-agent:来定义搜索引擎,其中*表示所有,Baiduspider表示百度蜘蛛,Googlebot表示谷歌蜘蛛。

也就是说User-agent:*表示定义所有蜘蛛,User-agent:Baiduspider表示定义百度蜘蛛。
常用搜索蜘蛛规则分解如下:
User-agent: Baiduspider
User-agent: Baiduspider-image
User-Agent: Googlebot
User-agent: Bingbot
User-Agent: 360Spider
User-Agent: Yisouspider
User-Agent: Sogouspider
User-agent: Sogou web spider
User-agent: Sogou inst spider
User-agent: Sogou spider2
User-agent: Sogou blog
User-agent: Sogou News Spider
User-agent: Sogou Orion spider
User-agent: ChinasoSpider
User-agent: Sosospider
User-Agent: Yahoo! Slurp
User-agent: MSNBot
User-agent: YoudaoBot
User-agent: EasouSpider

2、禁止与允许访问

Disallow: /表示禁止访问,Allow: /表示允许访问。

在写robots.txt时需特别注意的是,/前面有一个英文状态下的空格(必须是英文状态下的空格)。

3、禁止搜索引擎访问网站中的某几个文件夹,以a、b、c为例,写法分别如下:

Disallow: /a/

Disallow: /b/

Disallow: /c/

4、禁止搜索引擎访问文件夹中的某一类文件,以a文件夹中的js文件为例,写法如下:

Disallow: /a/*.js

5、只允许某个搜索引擎访问,以Baiduspider为例,写法如下:

User-agent: Baiduspider

Disallow:

6、禁止访问网站中的动态页面

User-agent: *

Disallow: /*?*

7、只允许搜索引擎访问某类文件,以htm为例,写法如下:

User-agent: *

Allow: .htm$

Disallow: /

8、禁止某个搜索引擎抓取网站上的所有图片,以Baiduspider为例,写法如下:

User-agent: F

Disallow: .jpg$

Disallow: .jpeg$

Disallow: .gif$

Disallow: .png$

Disallow: .bmp$

三、robots.txt文件存放位置

robots.txt文件存放在网站根目录下,并且文件名所有字母都必须小写。

四、特别注意事项

在写robots.txt文件时语法一定要用对,User-agent、Disallow、Allow、Sitemap这些词都必须是个字母大写,后面的字母小写,而且在:后面必须带一个英文字符下的空格。

网站上线之前切记写robots.txt文件禁止蜘蛛访问网站,如果不会写就先了解清楚写法之后再写,以免给网站收录带来不必要的麻烦。

robots.txt文件生效时间在几天至一个月之间,站长自身无法控制。但是,站长可以在百度统计中查看网站robots.txt文件是否生效。

本文标题:最详细的robots文件的写法解析(符合搜索需求)
当前路径:https://www.cdcxhl.com/news45/89595.html

成都网站建设公司_创新互联,为您提供网站制作搜索引擎优化网站改版小程序开发静态网站全网营销推广

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

猜你还喜欢下面的内容

营销型网站建设

网站建设知识

各行业网站