Add a sitemap to robots.txt

Sitemap: https://example.com/sitemap.xml

Add the line Sitemap: https://example.com/sitemap.xml to robots.txt, with your sitemap’s full URL. It needs the scheme and host: Google says it doesn’t guess http or https, www or not, and the sitemaps.org protocol asks for the full URL too. The tester flags a relative value such as /sitemap.xml under Lint. The line belongs to no User-agent group, so it can go anywhere in the file; after the groups is the clearest place.

User-agent: *
Disallow: /admin/

Sitemap: https://example.com/sitemap.xml
Sitemap: https://example.com/news-sitemap.xml

The tester lists both sitemaps under Lint and judges the rules as usual: /sitemap.xml is allowed, and /admin/login is disallowed by line 2. Google says Google, Bing and other major search engines read the field, and Common Crawl’s CCBot uses it as well.

Rules for the line

  • List as many as you need. Google sets no limit on Sitemap lines. With a sitemap index, listing the index alone is enough.
  • It can point to another host. Google and sitemaps.org both accept a sitemap stored elsewhere, such as https://sitemaps.example.com/sitemap-example-com.xml: listing it in a site’s own robots.txt is what vouches for it.
  • Keep the sitemap crawlable. Crawlers follow a listed sitemap only if it isn’t disallowed, Google’s spec says, so a rule like Disallow: /*.xml$ would hide it.
  • Mind the size. One sitemap holds at most 50,000 URLs and 50 MB uncompressed; split a bigger one and list the index.
  • It’s a hint. Google says a sitemap doesn’t guarantee it will be downloaded or used. Search Console’s Sitemaps report shows when Googlebot read it and what went wrong.

It doesn’t end a group

RFC 9309 (section 2.2.4) lets crawlers read records it doesn’t define, like Sitemap, but says they must not end a group. So a Sitemap line between two User-agent lines doesn’t separate them:

User-agent: Bingbot
Sitemap: https://example.com/sitemap.xml
User-agent: DuckDuckBot
Disallow: /search

Here Bingbot shares DuckDuckBot’s rules and is disallowed from /search?q=duck by line 4. Google’s robots.txt spec gives the same example. Sitemap lines at the end of the file avoid the surprise.

Elsewhere

Frameworks can write the file for you. In Next.js, app/robots.ts returns { rules, sitemap: 'https://example.com/sitemap.xml' }. WordPress adds a Sitemap: line for its own sitemap index to the robots.txt it generates, as long as the site is visible to search engines.

Try it in the Robots.txt Tester

Allowed No rule in the group for * matches /sitemap.xml: Googlebot may fetch it.

The group for * applied — 1 rule in the merged group.

The file, line by line · 6 lines
  1. 1User-agent: *
  2. 2Disallow: /admin/
  3. 3
  4. 4Sitemap: https://example.com/sitemap.xml
  5. 5Sitemap: https://example.com/news-sitemap.xml
  6. 6
Lint · 2 findings
  • Line 4: Sitemap listed: https://example.com/sitemap.xml
  • Line 5: Sitemap listed: https://example.com/news-sitemap.xml

Judged per RFC 9309, the Robots Exclusion Protocol: the longest matching rule wins, Allow wins a tie, and * with $ wildcards are matched by hand. Everything runs in this page, nothing is uploaded.

Runs in your browser. Nothing you enter is sent anywhere.