Sitemap or robots.txt: What Each One Does
A sitemap says "these are the pages I'd like you to find". A robots.txt file says "please stay out of these places". One invites. The other asks for restraint.
The sitemap, in one line
A sitemap tells search engines which pages and files you think are important on your site.1 It's a list of pages you hope people will find in search.
The robots.txt file, in one line
It tells crawlers which URLs they can access on your site. Google says its main use is to stop your server being swamped by requests.2
Picture a receptionist with a visitor list. The list says which rooms a guest may enter. It doesn't describe the building, and it doesn't promise every guest will obey.
Side by side
| Sitemap | robots.txt | |
|---|---|---|
| Main job | Lists pages you want found | Tells crawlers where they may go |
| Tone | An invitation | A request to stay out |
| Where it sits | Site root recommended; see below | Must be at the site root |
You can host a sitemap anywhere on your site, but unless you submit it through Search Console, it affects only URLs in its own directory and below. That is why Google recommends the site root.3 The robots.txt file has to sit at the root of the site host.4
A common mix-up
Leaving a page out of a sitemap doesn't hide it. Google says omitting or removing a URL from your sitemap doesn't prevent Google from crawling or indexing it, if it finds the page through links from other sites.1
The reverse is also true. Putting a rule in robots.txt doesn't keep a page out of search results. That has its own page, on blocked pages that still appear.
Short version: neither file is a privacy tool. Google says respectable crawlers obey a robots.txt file, but other crawlers might not.2
Here's a quick test. Ask what you want to happen to the page. If the answer is "I want it found", it belongs in a sitemap. If the answer is "I'd rather crawlers skipped it", think about robots.txt. If the answer is "nobody should see it", you need a password. Each file answers a different question.
How the two files meet
They can point to each other. You can add a line to your robots.txt file that gives the sitemap's address. The sitemaps.org protocol says you can specify the location of the Sitemap using a robots.txt file.5
Google adds that sitemaps are a good way to indicate which content Google should crawl, as opposed to which content it can or cannot crawl.4
The exact line is on How to Give Your Sitemap to Search Engines.
Which one do you need?
Start with the question you're asking.
- "How do I help search engines find my pages?" Use a sitemap. See What an XML Sitemap Is and What It Is For.
- "How do I ask crawlers to skip a folder?" Use robots.txt. See What a robots.txt File Is and Where It Lives.
- "How do I keep a page out of search?" Neither. Google points to other tools, such as password protection or a noindex rule.2
Cited material
- What Is a Sitemap, Google Search Central
- Robots.txt Introduction and Guide, Google Search Central
- Build and Submit a Sitemap, Google Search Central
- Create and Submit a robots.txt File, Google Search Central
- sitemaps.org Protocol, sitemaps.org