企业网站
官网站点地图和robots怎么配
sitemap.xml 让搜索引擎发现所有页面,robots.txt 控制搜索引擎抓取。本文讲清两者怎么配、常见错误和工具。
sitemap 和 robots 是官网 SEO 的基础设施——配置错误,搜索引擎抓不到你的页面、排名上不去。 这篇文章讲清两者怎么配。
sitemap.xml 是什么
sitemap.xml 是给搜索引擎的页面清单,告诉它:
- 你的网站有哪些页面。
- 页面的更新频率。
- 页面的优先级。
- 上次更新时间。
作用
- 帮搜索引擎发现页面(特别是新页面、深层页面)。
- 加速抓取。
- 提升索引效率。
必要性
- 必须有:新站、内容多、深层页面、内链弱。
- 建议有:所有官网。
- 可不要:极简站、所有页面首页直达。
sitemap.xml 格式
基础格式
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://example.com/</loc>
<lastmod>2026-02-28</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
<url>
<loc>https://example.com/about</loc>
<lastmod>2026-02-20</lastmod>
<changefreq>monthly</changefreq>
<priority>0.8</priority>
</url>
</urlset>
字段说明
| 字段 | 必填 | 说明 |
|---|---|---|
| loc | 是 | 页面 URL |
| lastmod | 否 | 最后修改时间 |
| changefreq | 否 | 更新频率(daily、weekly、monthly) |
| priority | 否 | 优先级(0.0 到 1.0) |
注意:changefreq 和 priority 是提示,搜索引擎不一定按此抓取。
sitemap index(大站)
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>https://example.com/sitemap-pages.xml</loc>
<lastmod>2026-02-28</lastmod>
</sitemap>
<sitemap>
<loc>https://example.com/sitemap-posts.xml</loc>
<lastmod>2026-02-28</lastmod>
</sitemap>
</sitemapindex>
sitemap 类型
1. 普通 sitemap
- 页面 sitemap。
- 最常用。
2. 图片 sitemap
- 图片清单。
- 帮助图片搜索。
3. 视频 sitemap
- 视频清单。
- 帮助视频搜索。
4. 新闻 sitemap
- 新闻内容。
- Google News。
5. 多语言 sitemap
- 含 hreflang。
- 多语言官网。
怎么生成 sitemap
1. 框架自动生成
| 框架 | 方案 |
|---|---|
| Nuxt | @nuxtjs/sitemap |
| Next.js | next-sitemap |
| Astro | @astrojs/sitemap |
| Hugo | 内置 |
| Eleventy | 插件 |
2. CMS 自动生成
| CMS | 方案 |
|---|---|
| WordPress | Yoast、RankMath 插件 |
| Drupal | 内置或模块 |
| Joomla | 内置或插件 |
3. 在线生成
- XML-Sitemaps.com。
- Screaming Frog(爬取生成)。
- 适合静态站。
4. 自定义脚本
- 从数据库生成。
- 自动化部署。
提交 sitemap
Google Search Console
- 添加网站。
- 验证。
- 提交 sitemap(
https://example.com/sitemap.xml)。 - 监控抓取状态。
百度站长平台
- 添加网站。
- 验证。
- 提交 sitemap。
- 监控抓取。
Bing Webmaster Tools
- 添加网站。
- 提交 sitemap。
robots.txt 提交
User-agent: *
Allow: /
Sitemap: https://example.com/sitemap.xml
robots.txt 是什么
robots.txt 是给搜索引擎的抓取指令,告诉它:
- 哪些页面可以抓。
- 哪些页面不能抓。
- sitemap 在哪。
位置
- 必须在根目录:
https://example.com/robots.txt。 - 大小写敏感(小写)。
作用
- 控制抓取(节省抓取预算)。
- 防止抓取敏感页面(后台、API)。
- 引导搜索引擎到 sitemap。
不作用
- 不是保密工具(robots.txt 是公开的,任何人能看到)。
- 不是索引控制(要 noindex)。
- 不是安全防护(要权限验证)。
robots.txt 格式
基础格式
User-agent: *
Allow: /
Disallow: /admin/
Disallow: /api/
Disallow: /search?
Sitemap: https://example.com/sitemap.xml
字段说明
| 字段 | 说明 |
|---|---|
| User-agent | 搜索引擎(* 是所有) |
| Allow | 允许抓取 |
| Disallow | 禁止抓取 |
| Sitemap | sitemap 位置 |
| Crawl-delay | 抓取延迟(部分支持) |
常见规则
# 允许所有
User-agent: *
Allow: /
# 禁止所有
User-agent: *
Disallow: /
# 禁止特定搜索引擎
User-agent: BadBot
Disallow: /
# 禁止特定目录
User-agent: *
Disallow: /admin/
Disallow: /private/
Disallow: /*.pdf$
# 允许特定
User-agent: Googlebot
Allow: /
# sitemap
Sitemap: https://example.com/sitemap.xml
配置建议
1. 允许抓取
- 所有公开内容页面。
- 静态资源(CSS、JS、图片)。
2. 禁止抓取
- 后台管理页面。
- API 接口。
- 搜索结果页(避免重复内容)。
- 用户私有页面。
- 临时、测试页面。
- 参数 URL(如
?session=)。
3. 谨慎禁止
- 不要禁止 CSS、JS(搜索引擎要渲染页面)。
- 不要禁止图片(影响图片搜索)。
- 不要禁止已收录页面(流量损失)。
常见错误
sitemap 错误
- 包含 404:死链。
- 包含 noindex:矛盾。
- 包含重定向:浪费。
- 超过限制:50000 URL、50MB。
- 不更新:新页面没加入。
- 格式错误:XML 错误。
robots.txt 错误
- 禁止全站:
Disallow: /,搜索引擎不抓。 - 禁止 CSS/JS:影响渲染。
- 大小写错误:
/Admin/不是/admin/。 - 通配符错:
*用错位置。 - 没 sitemap:搜索引擎找不到。
- 测试环境上线:开发时禁止抓取,上线忘改。
robots.txt vs noindex
| 工具 | 作用 | 适合 |
|---|---|---|
| robots.txt | 抓取控制 | 不想被抓的页面 |
| noindex | 索引控制 | 抓了但不想被收录 |
| canonical | 重复内容 | 重复页面指向主版本 |
| password | 完全保密 | 真正保密的页面 |
重要:robots.txt 屏蔽的页面如果被外链指向,搜索引擎仍可能收录。要彻底不收录用 noindex。
测试工具
Google Search Console
- robots.txt 测试工具。
- sitemap 测试工具。
- URL 检查工具。
百度站长平台
- robots 检测。
- sitemap 检测。
在线工具
- robots.txt Tester。
- Sitemap Validator。
现代框架的配置
Nuxt
// nuxt.config.ts
export default defineNuxtConfig({
modules: ['@nuxtjs/robots', '@nuxtjs/sitemap'],
site: {
url: 'https://example.com'
},
robots: {
UserAgent: '*',
Disallow: ['/admin', '/api'],
Sitemap: 'https://example.com/sitemap.xml'
}
})
Next.js
// app/robots.ts
export default function robots() {
return {
rules: { userAgent: '*', allow: '/', disallow: '/admin' },
sitemap: 'https://example.com/sitemap.xml'
}
}
成本参考
| 配置范围 | 成本 |
|---|---|
| 小站基础配置 | 含在建站 |
| 中站含自动生成 | 几百到几千 |
| 大站含多 sitemap | 几千到 1 万 |
| 持续监控 | 几百到几千/月 |
怎么开始
- 创建 robots.txt(允许公开、禁止敏感)。
- 创建 sitemap.xml(自动生成)。
- 在 robots.txt 中指向 sitemap。
- 提交到 Search Console、百度站长。
- 测试(用工具验证)。
- 监控抓取状态。
- 持续更新(新页面自动加入)。
广州市汉诺雷斯(HNREIS)做企业官网默认配置 robots.txt 和 sitemap.xml(自动生成、提交到搜索引擎),用 Nuxt 等现代框架内置 SEO 模块。把你的官网情况告诉我们,我们给出 sitemap 和 robots 配置方案。
常见问题
本文由 广州市汉诺雷斯(HNREIS) 整理。我们专注微信小程序开发、企业网站建设、外贸 B2B 独立站与 AI 智能体搭建,为企业提供从需求梳理到上线运维的全流程软件开发服务。
免费咨询需求