Sitemap vs. robots.txt β Definition and Differences
Compare the two files crawlers read first: one invites, one restricts. Learn what each controls and how they work together.
Both are files a crawler reads before doing anything else, and they do opposite jobs. A sitemap says "these pages exist, please look at them". robots.txt says "do not go here".
1. Key Differences
| Aspect | robots.txt |
Sitemap |
|---|---|---|
| Purpose | Restrict access | Aid discovery |
| Direction | Exclusion | Invitation |
| Format | Plain text directives | XML |
| Location | Always the site root | Anywhere, usually declared in robots.txt |
| Per-client rules | Yes, grouped by user agent | No |
| Enforcement | Voluntary compliance | Not applicable |
| Size limits | Practical only | Fifty thousand URLs, fifty megabytes uncompressed |
2. They Reference Each Other
robots.txt conventionally declares sitemap locations:
User-agent: *
Disallow: /admin/
Sitemap: https://example.com/sitemap.xml
This is why reading robots.txt first is the right order for any collector: it yields both the restrictions and the most efficient discovery route in one request.
3. Listing and Blocking the Same URL Is a Contradiction
A URL that appears in a sitemap and is disallowed in robots.txt sends conflicting signals. The block generally wins, and the sitemap entry is wasted β or worse, flagged as an error in webmaster tooling.
Keeping the two consistent is a basic hygiene check that many sites fail.
4. Neither Controls Indexing
This is the most consequential misunderstanding. robots.txt controls fetching; a sitemap suggests discovery. Neither decides whether a page is included in search results.
Indexing is controlled by page-level directives, and a page blocked in robots.txt can still be indexed from external signals β without a description, because the content was never read.
5. What Each Is Good For
robots.txt β keeping crawlers away from admin paths, infinite filter combinations, internal search, and anything whose crawling wastes budget. Also for stating a crawl delay.
Sitemaps β publishing an inventory, signalling last-modified times for incremental crawling, and surfacing pages that are poorly linked internally.
6. For Anyone Collecting Data
Read both, in this order:
robots.txtβ for the rules that apply to your client, and the sitemap locations.- The sitemap index and its files β for the URL inventory and
lastmodvalues.
That sequence respects the site's stated wishes and gets the inventory in a handful of requests rather than by crawling for it.
7. Common Mistakes on Both Sides
- Blocking a path in
robots.txtand expecting deindexing. - Listing blocked URLs in a sitemap.
- Publishing a sitemap with stale or fabricated
lastmodvalues. - Assuming
robots.txthides anything β listing a path advertises it. - Ignoring
robots.txtbecause it is unenforced.
8. Summary
robots.txt restricts crawling and is grouped by user agent; a sitemap invites discovery and carries optional metadata. robots.txt usually points at the sitemap.
Neither controls indexing. For collection, read robots.txt first for the rules and the sitemap location, then the sitemap for the inventory β the politest and cheapest possible start.