sitemap.xml 和 robots.txt

概述

每个网站都必须同时有 robots.txtsitemap.xml 文件,两者区别如下:

robots.txt :告知 SEO 哪些页面能够访问,哪些页面不能访问,即声明访问规则;

sitemap.xml :告知 SEO 网站结构图,也就是希望 SEO 抓取并呈现给用户的页面。

在 rebots.txt 允许的范围内,SEO 也会通过站内链接/外部链接去抓取 sitemap.xml 中之外的页面,只要这些页面没有被 robots 禁止。

注:主域名和子域名的 robots.txt / sitemap.xml 必须完全独立,主域名的 robots.txt / sitemap.xml 不应包含子域名的 URL,因为在SEO眼里,这是两个完全独立的网站;

注:在 SEO 眼里,所有的子域名都是独立的网站;

Robots.txt

网站可以没有 robots.txt 文件,没有不等于不规范,SEO 不会因此而惩罚网站;没有 robots.txt 就是默认允许所有爬虫抓取所有可访问 URL;但就算全站允许被抓取,也应该有 robots.txt,以便为 SEO 明确指路,让 SEO 更顺利的抓取和收录网站;最佳配置如下:

User-agent: *
Allow: /

Sitemap: https://tr.eztun.net/sitemap-index.xml

User-agent: * 表示当前规则适用于 所有搜索引擎爬虫,包括 Googlebot / Bingbot / Baiduspider / Yandex 等

Allow: / 表示允许抓取 整个站点的所有路径

Sitemap: https://tr.eztun.net/sitemap-index.xml 明确告知爬虫站点地图的位置;

Sitemap.xml

1>. 页面 sitemap.xml

以下是 sitemap.xml 的结构,其中 loc页面URL,lastmod 是页面内容最后一次的更新时间;

<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
  <url>
    <loc>https://tr.eztun.net/turf/blog</loc>
    <lastmod>2025-12-22</lastmod>
  </url>
  <url>
    <loc>https://tr.eztun.net/turf/blog/archive</loc>
    <lastmod>2025-12-22</lastmod>
  </url>
  <url>
    <loc>https://tr.eztun.net/turf/blog/authors</loc>
    <lastmod>2025-12-22</lastmod>
  </url>
  <url>
    <loc>https://tr.eztun.net/turf/</loc>
    <lastmod>2025-12-22</lastmod>
  </url>
</urlset>


2>. sitemap 索引

如果一个网站中有多个 sitemap.xml,则需要在根目录下放置一个索引 sitemap.xml , 该索引 sitemsp.xml 用于列出并告知 SEO 各 sitemap.xml 文件的位置;如下:

<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

  <sitemap>
    <loc>https://tr.eztun.net/turf/sitemap.xml</loc>
    <lastmod>2025-12-22</lastmod>
  </sitemap>

  <sitemap>
    <loc>https://tr.eztun.net/turf/zh-CN/sitemap.xml</loc>
    <lastmod>2025-12-22</lastmod>
  </sitemap>

</sitemapindex>

注:名称为 sitemap.xml 的文件并不是 SEO 默认寻找的网站地图文件; 如果网站中有多个 sitemap.xml ,SEO 找到哪个就用哪个,没有所谓的默认一说。最安全可靠的方式是主动在 SEO 站长平台提交 sitemap.xml ,或在 robots.txt 声明 sitemap.xml 的位置。

举报

© 著作权归作者所有


0