robots.txt生成器


工具介绍

本工具可快速生成robots.txt文件,控制搜索引擎爬虫访问权限。

使用方法

  1. 选择是否允许所有爬虫访问。
  2. 下方自动生成robots.txt内容,可复制或下载。

robots.txt书写教程与规范

  • User-agent:指定作用的搜索引擎爬虫名称,* 表示所有爬虫。
  • Disallow:禁止爬虫访问的路径或文件,Disallow: 后跟路径,留空表示允许全部访问。
  • Allow:允许爬虫访问的路径(优先级高于Disallow,部分搜索引擎支持)。
  • Sitemap:指定网站的sitemap地址(如 Sitemap: https://www.example.com/sitemap.xml)。
常见写法示例:
# 允许所有搜索引擎访问所有内容
User-agent: *
Disallow:

# 禁止所有搜索引擎访问网站
User-agent: *
Disallow: /

# 只禁止百度爬虫访问 /private/ 目录
User-agent: Baiduspider
Disallow: /private/

# 禁止所有爬虫访问 /admin/ 和 /login.html
User-agent: *
Disallow: /admin/
Disallow: /login.html

# 允许所有内容,但禁止 /tmp/ 目录
User-agent: *
Disallow: /tmp/
        
  • robots.txt 文件应放在网站根目录下。
  • 每个 User-agent 块可单独配置 Disallow/Allow。
  • 路径区分大小写,/admin/ 只影响 /admin/ 下内容。
  • robots.txt 仅对遵守协议的爬虫有效,恶意爬虫可能无视。
更多规范可参考 Google官方robots.txt说明