How do you add a sitemap to robots.txt?

By TechCompare · Updated · How we check

Use one Sitemap line per file, with a fully qualified URL. The line applies to every crawler, and the sitemap can live on another host.

A Sitemap line in robots.txt tells crawlers where your sitemap lives. Write the full address, like Sitemap: https://www.example.com/sitemap.xml. Put it anywhere in the file. You can add several lines, one per sitemap or index. It belongs to no crawler group, so every crawler that reads the file can use it.

Topic
Sitemap line in robots.txt
Sitemap line
Category
Sitemaps
Limits, dates and the Sitemap line

How it works

Google's documentation says the sitemap URL must be fully qualified, so a path like /sitemap.xml doesn't count. The sitemaps.org protocol agrees that the line can go anywhere in the file and that several lines are fine. The tester reads every Sitemap line and reports each file. When the file lists none, it tries /sitemap.xml and says so, since that's a guess and not a statement from the site. It also tests the URLs in the sitemaps against the rules for every crawler in the table, and tells you how many are blocked for each, with examples. A URL that sits in a sitemap and is blocked in robots.txt contradicts itself: the sitemap offers the page and the rules refuse to let the crawler fetch it. The same check shows a sample of sitemap URLs that redirect or fail, because a sitemap should list the address pages actually answer on.

Verdict

List your sitemap index, or each sitemap if you don't have one, with full URLs. Then read the report. Files that don't load, URLs your rules block, and bad lastmod dates are the three things worth fixing first.

More Robots.txt scenarios

Block GPTBot
Two lines tell OpenAI's training crawler to stay out. Its search crawler and its page visits use other names.
View details
Google-Extended
A token for Gemini training, not a crawler. A rule for it never reaches Googlebot or Google Search.
View details
Block AI, keep search
Name each training crawler, leave Googlebot and Bingbot alone, and choose on purpose about the AI search bots.
View details

Frequently asked questions

Does the Sitemap line have to sit under a User-agent line?
No. Google says it isn't tied to any user agent, and the sitemaps protocol lets it go anywhere in the file.
Can the sitemap be on a different host than robots.txt?
Google says the URL doesn't have to be on the same host as the robots.txt file. Write it as a full address either way.
What if robots.txt lists no sitemap?
The tester tries /sitemap.xml and marks it as a default guess. Add a Sitemap line so nobody has to guess, and so the report reads the file you mean.