An XML sitemap is a file that lists the URLs you want search engines to index. Robots.txt is a file that tells crawlers which parts of a site they may fetch. One invites, the other restricts, and both sit at the root of the domain. This guide explains what each should contain, how to set them up and the mistakes that cause indexing problems.
What an XML sitemap is
A sitemap is an XML file, usually at /sitemap.xml, with one entry per URL:
<url>
<loc>https://www.example.com/services/</loc>
<lastmod>2026-11-20</lastmod>
</url>
It helps Google discover pages, especially on new sites, large sites and sites with few internal links. It is a suggestion: listing a URL does not guarantee indexing.
What a sitemap should contain
- Only canonical URLs that return a 200 status and should be indexed.
- No redirects, error pages,
noindexpages or parameter duplicates. - An accurate
lastmod. Google uses it when it proves reliable;priorityandchangefreqare ignored. - At most 50,000 URLs or 50 MB per file. Larger sites use a sitemap index.
Creating and submitting
- Generate it automatically. Most platforms and SEO plugins do. A hand-made file goes stale.
- Open it in a browser to confirm it loads and lists the right pages.
- Submit it in Search Console under Sitemaps. See Google Search Console.
- Reference it in robots.txt.
- Check the report for errors and for the gap between submitted and indexed pages.
What robots.txt is
Robots.txt is a plain text file at /robots.txt:
User-agent: *
Disallow: /cart/
Disallow: /search/
Sitemap: https://www.example.com/sitemap.xml
User-agentnames the crawler a group of rules applies to.Disallowblocks a path.Allowmakes an exception.Sitemappoints to the sitemap.

Reputable crawlers follow these rules. The file is public and is not a security measure.
Robots.txt is not noindex
Robots.txt controls crawling. It does not control indexing.
- A URL blocked in robots.txt can still be indexed if other pages link to it, shown without a description.
- To keep a page out of the index, use a
noindextag and leave the page crawlable so Google can read the tag. - Blocking a page and adding
noindextogether defeats the purpose.

See Google indexing.
What to block
- Cart, checkout and account pages.
- Internal search results.
- Filter and sort parameters with no search value.
- Admin and API paths.

What not to block:
- CSS and JavaScript that pages need to render.
- Pages you want indexed.
- Pages carrying a
noindexyou want Google to see.
Key point The sitemap says “look at these pages”. Robots.txt says “stay out of these places”. Neither replaces a noindex tag.
Robots.txt and AI crawlers
AI companies run their own crawlers with their own user-agent names, some for training and some for answering questions live. You can allow or block each one in robots.txt. Blocking the crawlers that fetch pages for answers also removes the chance of being cited there, so decide deliberately. See generative engine optimization.
Common mistakes
Disallow: /left over from development, blocking the whole site.- A sitemap full of redirects, 404s or
noindexpages. - Blocking CSS or JavaScript.
- Using robots.txt to hide private content.
- A sitemap that is never updated.
- Different rules on the www and non-www versions.
How to check
- Open
/robots.txtand/sitemap.xmlin a browser. - Use URL Inspection in Search Console to see whether a URL is blocked.
- Read the robots.txt report in Search Console settings.
- Crawl the sitemap with a site crawler to find non-200 URLs.
Frequently asked questions
Does a small site need a sitemap?
It can manage without one if pages are well linked, but a sitemap costs nothing and makes reporting in Search Console clearer.
Is an HTML sitemap needed?
Not for search engines. It can help visitors on large sites.
What if there is no robots.txt?
Crawlers assume they may fetch everything. A small site with nothing to block works normally.
Both files are on the checklist for an SEO-friendly website and part of technical SEO. If you would like them checked, send your domain for a free audit.
Further reading
Official documentation and reference pages on this topic:
- Build and submit a sitemap (Google Search Central): sitemap formats and the ways to submit one.
- How Google interprets the robots.txt specification (Google): file location, syntax and how rules are matched.
