---
title: "【转】如何设置robots.txt文件"
author: "flyer0126"
date: "2014-07-03T18:32:54Z"
tags: ["robots"]
categories: ["Web前端"]
slug: "robots-txt"
draft: false
lastmod: "2014-07-03T18:32:43Z"
id: 2088061
url: "https://flyer0126.iteye.com/blog/2088061"
---

robots.txt是搜索引擎用来爬取网页内容的工具我们称之为搜索引擎机器人。  
搜索引擎机器人每次来到要抓取的网站，都会先访问这个网站根目录下的一个文件（robots.txt），如果不存在该文件，则搜索引擎机器人默认这个网站允许其全部抓取。

   robots.txt是一个简单的纯文本文件（记事本文件），搜索引擎机器人通过robots.txt里的“说明”，理解该网站是否可以全部抓取或部分抓取。

    如果你希望搜索引擎收录你网站的全部网页，则你可以不设置robots.txt或上传一个命名为robots.txt的空记事本到根本目录。  
      上传你的robots.txt后，通过 你的域名/robots.txt 可以正常访问。 注意，robots.txt的命名，都应该是小写  
robots.txt文件的内容主要就是一个代码：Disallow:  
注意，robots.txt文件中一定要包含一个Disallow:  
如果都允许收录，你可以写一行Disallow:/search.html 这个文件(search.html)本来就不存在也没事。

格式如：  
Disallow: /search.html  
|Disallow: /index.php?  
Disallow: /tempweb/

说明：  
User-agent: * 星号说明，允许所有的搜索引擎来收录，包括百度、google、yahoo等。  
Disallow: /search.html 说明不允许收录 /search.html 这个文件。  
Disallow: /index.php? 说明不允许收录以index.php?为前缀的链接如：index.php?122.html、index.php?=12、index.php?/baidu等等  
Disallow: /tempweb/ 说明不允许收录/tempweb/里的所有文件。但可以收录如：/tempwebtaim.html 的链接。

这里介绍的是常用的几个代码。  
如果需要了解更多关于Disallow:的用法，请了解百度官方的介绍：[http://www.baidu.com/search/robots.html](http://www.baidu.com/search/robots.html)

1、当你的网页已被收录，但想用robots.txt删除掉，一般需要1-2个月。  
2、结合Google网站管理员工具，你可以马上删除被Google收录的网页。

 

参考文章：[http://www.seoweb-sh.com/208.html](http://www.seoweb-sh.com/208.html)