xml-sitemap
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSEO Technical: Sitemap
SEO技术:Sitemap
Guides sitemap creation, auditing, and optimization for search engine discovery.
When invoking: On first use, if helpful, open with 1–2 sentences on what this skill covers and why it matters, then provide the main output. On subsequent use or when the user asks to skip, go directly to the main output.
指导sitemap的创建、审核和优化,助力搜索引擎发现站点内容。
调用规则:首次使用时,如果有帮助,可以先用1-2句话介绍本技能覆盖的内容及其重要性,再提供核心输出。后续使用或用户要求跳过介绍时,直接给出核心输出即可。
Scope (Technical SEO)
适用范围(技术SEO)
- Sitemap: Create XML sitemap; submit to Google Search Console
- URL discovery: Help search engines find pages; especially important for large sites or poor internal linking
- Sitemap:创建XML sitemap;提交到Google Search Console
- URL发现:帮助搜索引擎找到站点页面,对大型站点或内链结构不完善的站点尤为重要
Task
任务
Generate an XML Sitemap that complies with the sitemaps.org protocol from the project's page list, and declare it in robots.txt.
根据项目的页面列表生成符合sitemaps.org协议的XML Sitemap,并在robots.txt中声明。
Initial Assessment
初始评估
Check for product marketing context first: If or exists, read it for site URL and page structure.
.claude/product-marketing-context.md.cursor/product-marketing-context.mdIdentify:
- Site URL: Base domain (e.g., )
https://example.com - URL count: Total indexable pages (single sitemap vs. sitemap index)
- Data source: Static config, CMS, file system, or hybrid
优先检查产品营销上下文:如果存在或,读取文件获取站点URL和页面结构信息。
.claude/product-marketing-context.md.cursor/product-marketing-context.md确认以下信息:
- 站点URL:基础域名(例如)
https://example.com - URL数量:可被索引的页面总数量(决定使用单个sitemap还是sitemap索引)
- 数据来源:静态配置、CMS、文件系统或混合模式
1. Protocol Essentials
1. 协议核心要求
| Item | Spec |
|---|---|
| Single sitemap limit | 50,000 URLs, 50MB (uncompressed) |
| Sitemap index | When exceeding limit, split and have main index reference sub-sitemaps |
| Encoding | UTF-8 |
| URL format | Full URL, same host, include |
| Required tags | |
| Optional tags | |
| 条目 | 规范 |
|---|---|
| 单个sitemap限制 | 50,000个URL,50MB(未压缩状态) |
| Sitemap索引 | 超出限制时拆分sitemap,通过主索引文件引用子sitemap |
| 编码 | UTF-8 |
| URL格式 | 完整URL,和站点同域名,需包含 |
| 必填标签 | |
| 可选标签 | |
2. Field Requirements
2. 字段要求
| Field | Description | Recommendation |
|---|---|---|
| url | Full URL | |
| lastModified | Page last modified time | Use page metadata, ISO 8601; use |
| changeFrequency | Update frequency | Home |
| priority | Relative importance | Home 1.0, aggregate pages 0.9, content pages 0.7–0.8, others 0.5–0.6 |
| 字段 | 说明 | 建议值 |
|---|---|---|
| url | 完整URL | |
| lastModified | 页面最后修改时间 | 使用页面元数据,遵循ISO 8601格式;无数据时使用 |
| changeFrequency | 页面更新频率 | 首页 |
| priority | 页面相对重要性 | 首页1.0,聚合页0.9,内容页0.7–0.8,其他页面0.5–0.6 |
lastmod (Critical)
lastmod(核心字段)
- Must be accurate: Reflect actual page modification time, not sitemap generation time. Google requires verifiability; Bing reports ~18% of sitemaps ignored due to lastmod errors.
- Format: W3C Datetime (or
YYYY-MM-DD), e.g.YYYY-MM-DDTHH:MM:SS+TZD,2025-01-15.2025-01-15T14:30:00+08:00 - Avoid: Using for lastmod—causes all URLs to share the same timestamp; search engines may ignore.
new Date() - Apply when: Content updates, structured data changes, or important link changes.
- 必须准确:需反映页面实际修改时间,而非sitemap生成时间。Google要求该字段可验证;Bing报告约18%的sitemap因lastmod错误被忽略。
- 格式:W3C Datetime格式(或
YYYY-MM-DD),例如YYYY-MM-DDTHH:MM:SS+TZD、2025-01-15。2025-01-15T14:30:00+08:00 - 注意事项:不要使用生成lastmod,这会导致所有URL使用相同时间戳,可能被搜索引擎忽略。
new Date() - 触发更新场景:内容更新、结构化数据变更、重要链接变更时更新该字段。
changefreq / priority
changefreq / priority
- changefreq: Hints only; does not directly determine crawl frequency. Values: ,
always,hourly,daily,weekly,monthly,yearly.never - priority: 0.0–1.0; does not affect ranking; set higher for important pages; avoid identical values for all.
- changefreq:仅作参考,不会直接决定搜索引擎爬取频率。可选值:、
always、hourly、daily、weekly、monthly、yearly。never - priority:取值范围0.0–1.0,不影响搜索排名,重要页面可设置更高值,避免所有页面使用相同值。
3. Architecture & Split
3. 结构与拆分规则
Single Sitemap
单个Sitemap
- When URLs >50,000, generate directly.
/sitemap.xml
- URL数量≤50,000时,直接生成即可。
/sitemap.xml
Sitemap Index (Multiple Sub-sitemaps)
Sitemap索引(多个子Sitemap)
- When exceeding limit, split by type or language; main index references sub-sitemaps.
- Example splits: ,
/sitemap/posts.xml,/sitemap/pages.xml,/sitemap/zh.xml./sitemap/en.xml - Main index outputs or
/sitemap.xml, each entry as/sitemap-index.xml.<sitemap><loc>...</loc></sitemap>
- 超出单个sitemap限制时,按页面类型或语言拆分,通过主索引文件引用所有子sitemap。
- 拆分示例:、
/sitemap/posts.xml、/sitemap/pages.xml、/sitemap/zh.xml。/sitemap/en.xml - 主索引文件输出为或
/sitemap.xml,每个条目格式为/sitemap-index.xml。<sitemap><loc>...</loc></sitemap>
Multilingual Sites
多语言站点
- Split by locale: ,
/sitemap/zh.xml./sitemap/en.xml - Or by content type + language: ,
/sitemap/zh-posts.xml./sitemap/en-posts.xml
- 按地域/语言拆分:、
/sitemap/zh.xml。/sitemap/en.xml - 或按内容类型+语言拆分:、
/sitemap/zh-posts.xml。/sitemap/en-posts.xml
Multi-Language Sitemap (hreflang in Sitemap)
多语言Sitemap(Sitemap中嵌入hreflang)
For multilingual sites, add hreflang alternates inside each entry. Recommended for large sites (100+ multilingual pages); centralizes hreflang management.
xhtml:link<url>Rules:
- Every language version must link to ALL others, including itself (self-reference).
- Include pointing to default locale.
x-default - Use namespace.
xmlns:xhtml="http://www.w3.org/1999/xhtml" - typically uses default-locale (clean) URL;
<loc>points there too.x-default
xml
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url>
<loc>https://example.com/page</loc>
<xhtml:link rel="alternate" hreflang="en" href="https://example.com/page" />
<xhtml:link rel="alternate" hreflang="zh" href="https://example.com/zh/page" />
<xhtml:link rel="alternate" hreflang="x-default" href="https://example.com/page" />
</url>
</urlset>List all language sitemaps in sitemap index; include in robots.txt.
多语言站点可在每个条目内添加 hreflang替代链接。推荐大型站点(100+多语言页面)使用,可集中管理hreflang配置。
<url>xhtml:link规则:
- 每个语言版本必须链接到所有其他语言版本,包括自身(自引用)。
- 包含指向默认语言版本。
x-default - 需使用命名空间。
xmlns:xhtml="http://www.w3.org/1999/xhtml" - 通常使用默认语言的干净URL,
<loc>也指向该地址。x-default
xml
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url>
<loc>https://example.com/page</loc>
<xhtml:link rel="alternate" hreflang="en" href="https://example.com/page" />
<xhtml:link rel="alternate" hreflang="zh" href="https://example.com/zh/page" />
<xhtml:link rel="alternate" hreflang="x-default" href="https://example.com/page" />
</url>
</urlset>在sitemap索引中列出所有语言的sitemap,并在robots.txt中声明。
4. Implementation
4. 实现方式
| Tech Stack | Implementation |
|---|---|
| Next.js App Router | |
| Next.js Pages Router | |
| Astro | |
| Vite / Static build | Build script generates |
| Other | Generate static |
| 技术栈 | 实现方案 |
|---|---|
| Next.js App Router | |
| Next.js Pages Router | |
| Astro | |
| Vite / 静态构建 | 通过构建脚本生成 |
| 其他技术栈 | 生成静态 |
Route Exclusion
路由排除
- If the project has i18n / middleware redirects, exclude sitemap paths to avoid redirect.
- Example (Next.js matcher): .
'/((?!api|_next|sitemap|sitemap-index|.*\\..*).*)'
- 如果项目有i18n/中间件重定向逻辑,需排除sitemap路径避免被重定向。
- 示例(Next.js matcher规则):。
'/((?!api|_next|sitemap|sitemap-index|.*\\..*).*)'
5. Page Scope
5. 页面范围
Include
需包含的页面
- Home:
/ - Locale/region home pages (e.g. ,
/zh)/en - All indexable content pages, list pages, category pages
- 首页:
/ - 多语言/多地域首页(例如、
/zh)/en - 所有可被索引的内容页、列表页、分类页
Exclude
需排除的页面
- ,
/api/*,/admin/*/_next/* - Static assets (images, JS, CSS, etc.). For image discovery, use image sitemap extension—see image-optimization
- Login, admin, drafts, and other pages not intended for indexing
- 、
/api/*、/admin/*/_next/* - 静态资源(图片、JS、CSS等),图片收录可使用图片sitemap扩展,参考image-optimization相关规范
- 登录页、管理页、草稿页等不希望被索引的页面
6. Data Source & Maintenance (Single Source of Truth)
6. 数据来源与维护(单一可信源)
- Single source of truth: Read URL list from config, CMS, or metadata; avoid hardcoding in sitemap.
- Multiple page types: Tools, blog, marketing pages can be merged into one array for unified generation.
- New pages: Add only to data source; sitemap updates automatically; avoid maintaining multiple places.
- 单一可信源:从配置文件、CMS或元数据中读取URL列表,避免在sitemap中硬编码URL。
- 多页面类型场景:工具页、博客页、营销页可合并到同一个数组统一生成。
- 新增页面:仅需在数据来源中添加,sitemap会自动更新,避免多位置维护。
Central Config (Recommended)
集中配置(推荐)
Create a config (e.g., ) that exports:
site-pages-config.ts- Page slugs/paths by section (tools, blog, marketing, etc.)
- Optional: per page for accurate lastmod
modifiedDate - Function: for sitemap and IndexNow
getAllPageUrls(baseUrl)
Why: Sitemap, IndexNow, and feed can all import from the same config—no duplicate URL maintenance. IndexNow should use the same URL list; avoid separate hardcoded lists.
创建配置文件(例如),导出以下内容:
site-pages-config.ts- 按模块划分的页面slug/路径(工具、博客、营销页等)
- 可选:每个页面的,用于生成准确的lastmod
modifiedDate - 工具函数:,供sitemap和IndexNow使用
getAllPageUrls(baseUrl)
优势:Sitemap、IndexNow、Feed都可以从同一个配置导入,无需重复维护URL列表。IndexNow应使用相同的URL列表,避免单独维护硬编码列表。
7. robots.txt
7. robots.txt配置
Add to robots.txt:
Sitemap: https://example.com/sitemap.xmlWith multiple sitemaps, only declare the main index.
在robots.txt中添加以下内容:
Sitemap: https://example.com/sitemap.xml如果有多个sitemap,仅声明主索引文件即可。
8. Output Format
8. 输出示例
Single Sitemap Example
单个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>2025-01-15</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
<url>
<loc>https://example.com/page</loc>
<lastmod>2025-01-10</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
</urlset>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>2025-01-15</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
<url>
<loc>https://example.com/page</loc>
<lastmod>2025-01-10</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
</urlset>Sitemap Index Example
Sitemap索引示例
xml
<?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>2025-01-15</lastmod>
</sitemap>
<sitemap>
<loc>https://example.com/sitemap/posts.xml</loc>
<lastmod>2025-01-14</lastmod>
</sitemap>
</sitemapindex>xml
<?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>2025-01-15</lastmod>
</sitemap>
<sitemap>
<loc>https://example.com/sitemap/posts.xml</loc>
<lastmod>2025-01-14</lastmod>
</sitemap>
</sitemapindex>9. Common Issues
9. 常见问题
| Issue | Cause / Fix |
|---|---|
| Sitemap 404 | Build failure, wrong path, incorrect export; check routes and deployment |
| Missing pages | URLs not in data source, filtered or excluded |
| lastmod anomaly | Avoid |
| Google not indexing | Submit sitemap in GSC; check Coverage (google-search-console) and robots |
| EN/ZH URL mismatch | Use unified data source; share same list when generating by locale |
| 问题 | 原因/解决方案 |
|---|---|
| Sitemap返回404 | 构建失败、路径错误、导出配置不正确;检查路由配置和部署状态 |
| 页面缺失 | URL未加入数据来源、被过滤或排除 |
| lastmod异常 | 避免使用 |
| Google未收录页面 | 在GSC中提交sitemap;检查Coverage(google-search-console)和robots配置 |
| 中英文URL不匹配 | 使用统一的数据来源,按语言生成sitemap时共享同一套URL列表 |
References
参考资料
Related Skills
相关技能
- website-structure: Plan page structure and URL list; sitemap reflects planned/indexable pages
- google-search-console: Sitemap status, indexed URL count, Coverage
- robots-txt: Reference sitemap in robots.txt
- indexnow: Share same URL list from config
- image-optimization: Image sitemap extension for image discovery
- website-structure:规划页面结构和URL列表,sitemap反映规划的可索引页面
- google-search-console:查看sitemap状态、已收录URL数量、Coverage报告
- robots-txt:在robots.txt中引用sitemap
- indexnow:和sitemap共享同一套URL配置
- image-optimization:使用图片sitemap扩展实现图片收录