xml-sitemap

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

SEO 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
.claude/product-marketing-context.md
or
.cursor/product-marketing-context.md
exists, read it for site URL and page structure.
Identify:
  1. Site URL: Base domain (e.g.,
    https://example.com
    )
  2. URL count: Total indexable pages (single sitemap vs. sitemap index)
  3. Data source: Static config, CMS, file system, or hybrid
优先检查产品营销上下文:如果存在
.claude/product-marketing-context.md
.cursor/product-marketing-context.md
,读取文件获取站点URL和页面结构信息。
确认以下信息:
  1. 站点URL:基础域名(例如
    https://example.com
  2. URL数量:可被索引的页面总数量(决定使用单个sitemap还是sitemap索引)
  3. 数据来源:静态配置、CMS、文件系统或混合模式

1. Protocol Essentials

1. 协议核心要求

ItemSpec
Single sitemap limit50,000 URLs, 50MB (uncompressed)
Sitemap indexWhen exceeding limit, split and have main index reference sub-sitemaps
EncodingUTF-8
URL formatFull URL, same host, include
https://
Required tags
<loc>
Optional tags
<lastmod>
,
<changefreq>
,
<priority>
条目规范
单个sitemap限制50,000个URL,50MB(未压缩状态)
Sitemap索引超出限制时拆分sitemap,通过主索引文件引用子sitemap
编码UTF-8
URL格式完整URL,和站点同域名,需包含
https://
必填标签
<loc>
可选标签
<lastmod>
<changefreq>
<priority>

2. Field Requirements

2. 字段要求

FieldDescriptionRecommendation
urlFull URL
https://example.com/path
lastModifiedPage last modified timeUse page metadata, ISO 8601; use
YYYY-MM-DD
or omit when no data
changeFrequencyUpdate frequencyHome
daily
, list pages
weekly
, content pages
monthly
priorityRelative importanceHome 1.0, aggregate pages 0.9, content pages 0.7–0.8, others 0.5–0.6
字段说明建议值
url完整URL
https://example.com/path
lastModified页面最后修改时间使用页面元数据,遵循ISO 8601格式;无数据时使用
YYYY-MM-DD
格式或省略该字段
changeFrequency页面更新频率首页
daily
,列表页
weekly
,内容页
monthly
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 (
    YYYY-MM-DD
    or
    YYYY-MM-DDTHH:MM:SS+TZD
    ), e.g.
    2025-01-15
    ,
    2025-01-15T14:30:00+08:00
    .
  • Avoid: Using
    new Date()
    for lastmod—causes all URLs to share the same timestamp; search engines may ignore.
  • 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
  • 注意事项:不要使用
    new Date()
    生成lastmod,这会导致所有URL使用相同时间戳,可能被搜索引擎忽略。
  • 触发更新场景:内容更新、结构化数据变更、重要链接变更时更新该字段。

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
    /sitemap.xml
    directly.
  • 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
    /sitemap.xml
    or
    /sitemap-index.xml
    , each entry as
    <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
xhtml:link
hreflang alternates inside each
<url>
entry. Recommended for large sites (100+ multilingual pages); centralizes hreflang management.
Rules:
  • Every language version must link to ALL others, including itself (self-reference).
  • Include
    x-default
    pointing to default locale.
  • Use
    xmlns:xhtml="http://www.w3.org/1999/xhtml"
    namespace.
  • <loc>
    typically uses default-locale (clean) URL;
    x-default
    points there too.
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.
多语言站点可在每个
<url>
条目内添加
xhtml:link
hreflang替代链接。推荐大型站点(100+多语言页面)使用,可集中管理hreflang配置。
规则
  • 每个语言版本必须链接到所有其他语言版本,包括自身(自引用)。
  • 包含
    x-default
    指向默认语言版本。
  • 需使用
    xmlns:xhtml="http://www.w3.org/1999/xhtml"
    命名空间。
  • <loc>
    通常使用默认语言的干净URL,
    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 StackImplementation
Next.js App Router
app/sitemap.ts
export
MetadataRoute.Sitemap
or
generateSitemaps
Next.js Pages Router
pages/sitemap.xml.ts
or
getServerSideProps
return XML
Astro
src/pages/sitemap-index.xml.ts
or
@astrojs/sitemap
Vite / Static buildBuild script generates
public/sitemap.xml
OtherGenerate static
/sitemap.xml
or return dynamically via API
技术栈实现方案
Next.js App Router
app/sitemap.ts
导出
MetadataRoute.Sitemap
或使用
generateSitemaps
Next.js Pages Router
pages/sitemap.xml.ts
或通过
getServerSideProps
返回XML
Astro
src/pages/sitemap-index.xml.ts
或使用
@astrojs/sitemap
插件
Vite / 静态构建通过构建脚本生成
public/sitemap.xml
其他技术栈生成静态
/sitemap.xml
或通过API动态返回

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.,
site-pages-config.ts
) that exports:
  • Page slugs/paths by section (tools, blog, marketing, etc.)
  • Optional:
    modifiedDate
    per page for accurate lastmod
  • Function:
    getAllPageUrls(baseUrl)
    for sitemap and IndexNow
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/路径(工具、博客、营销页等)
  • 可选:每个页面的
    modifiedDate
    ,用于生成准确的lastmod
  • 工具函数:
    getAllPageUrls(baseUrl)
    ,供sitemap和IndexNow使用
优势:Sitemap、IndexNow、Feed都可以从同一个配置导入,无需重复维护URL列表。IndexNow应使用相同的URL列表,避免单独维护硬编码列表。

7. robots.txt

7. robots.txt配置

Add to robots.txt:
Sitemap: https://example.com/sitemap.xml
With 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. 常见问题

IssueCause / Fix
Sitemap 404Build failure, wrong path, incorrect export; check routes and deployment
Missing pagesURLs not in data source, filtered or excluded
lastmod anomalyAvoid
new Date()
; use
modifiedDate
from page metadata
Google not indexingSubmit sitemap in GSC; check Coverage (google-search-console) and robots
EN/ZH URL mismatchUse unified data source; share same list when generating by locale
问题原因/解决方案
Sitemap返回404构建失败、路径错误、导出配置不正确;检查路由配置和部署状态
页面缺失URL未加入数据来源、被过滤或排除
lastmod异常避免使用
new Date()
,使用页面元数据中的
modifiedDate
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扩展实现图片收录