robots.txt and XML Sitemaps: What They Do and How to Get Them Right
On this page
- Common Mistakes to Avoid
- What robots.txt actually is
- The mistakes that cost real traffic
- What an XML sitemap is for
- What belongs in it
- Keeping it honest
- How to check both files in two minutes
- Submitting, and what the numbers mean
- noindex versus robots.txt, one more time
- The five-minute quarterly review
- A worked example
- The two-minute verification
These two files are the least glamorous part of a website and the most common cause of pages that never appear in search. One tells crawlers what they may fetch; the other tells them what exists. Get either wrong and the rest of your SEO work has nothing to work on.
What robots.txt actually is
A plain text file at the root of your domain, at /robots.txt. It is fetched before anything else and it applies to the whole site. It does not prevent a page appearing in results — it prevents the crawler fetching it, which usually has the same effect while also removing any chance of the page being indexed on its merits.
A sensible file for most sites is four lines:
- User-agent: *
- Allow: /
- Sitemap: https://example.com/sitemap.xml
That is it. Allow everything, declare the sitemap, stop.
The mistakes that cost real traffic
- Blocking CSS and JavaScript. Google renders pages to judge them. If the styling and scripts are blocked, it sees a different page from your visitors and may decide it is thin.
- A stray "Disallow: /" left in from a staging setup. This blocks the entire site, and it is the single most common catastrophic error in this file.
- Blocking the sitemap itself. Pointless and counterproductive.
- Using robots.txt to hide a page. A blocked URL can still be indexed if other sites link to it. Use noindex for that, and let the crawler fetch the page to see it.
- Assuming it protects anything. It is a request, not a security measure. A scraper can ignore it entirely.
What an XML sitemap is for
A sitemap lists the URLs you want found, with optional hints about when each last changed. It does not guarantee indexing and it is not a ranking factor. What it does is remove guesswork: a crawler that arrives at a new site with no internal links yet has a complete list of what to fetch.
For a site with clear navigation, a sitemap is a convenience. For a new site, a large site, or a site whose pages are hard to reach by clicking, it is essential.
What belongs in it
- Canonical URLs only. If a page has variants, list the one the canonical tag names.
- Pages that return 200. A sitemap full of redirects and 404s wastes crawl budget and signals neglect.
- Pages you want indexed. Not thank-you pages, not internal search results, not admin screens.
- Fewer than 50,000 URLs and under 50MB uncompressed per file. Beyond that, split it.
Keeping it honest
The most common sitemap problem is drift: the file lists pages that were deleted months ago and misses pages added since. If you generate it by hand, it will be wrong within a month.
Generate it from the site itself, at build or publish time. On a static site that is a few lines of script; on a CMS it is usually a plugin. Either way the principle holds: the sitemap should be a byproduct of the site, never a document somebody edits.
How to check both files in two minutes
- Open yourdomain.com/robots.txt. You should see plain text. If you see an HTML page, the file does not exist and your server is returning its 404 page instead.
- Read it for Disallow: / with nothing after it. That blocks everything.
- Open yourdomain.com/sitemap.xml. It should start with an XML declaration and contain <urlset>.
- Pick three URLs from the sitemap at random and load them. All three should return the page, not a redirect or an error.
- Submit the sitemap in Search Console and check the discovered count matches your expectation.
Submitting, and what the numbers mean
In Search Console, Sitemaps accepts the path and reports status, last read and discovered pages. "Success" means Google could read the file, nothing more. Discovered pages will usually exceed indexed pages, especially on a new site, and that gap is normal rather than a fault.
If the status is "Couldn't fetch", the file is missing, blocked, or returning an error. If discovered pages is lower than expected, compare the sitemap against the site: something is not being listed.
noindex versus robots.txt, one more time
Use noindex when a page exists but should not appear in results, such as a thank-you page or a staging copy. Use robots.txt when you want to reduce crawling of a section that does not need to be fetched at all, such as faceted filter URLs. Never use both on the same URL, because a blocked page cannot be crawled to see the noindex, and it may still be indexed from external links.
The five-minute quarterly review
Fetch both files, check three random sitemap URLs, confirm nothing important is disallowed, and make sure the sitemap was regenerated after your last content change. That is the whole discipline, and it prevents the most expensive class of invisible failure on a website.
A worked example
A site's robots.txt returns a "Page not found" HTML document instead of plain text, and its sitemap lists exactly one URL because the site is a single-page application. Google indexes the one page and reports nothing wrong, because from its point of view there is nothing else to find.
The interesting part is the sitemap: it is not broken, it is honest. A one-page site should have a one-URL sitemap. The failure is upstream, in the site having only one page to list.
When a sitemap reports far fewer URLs than you expect, check the generator before the file. If the site genuinely has one page, no amount of sitemap work will change the index.
The two-minute verification
- Fetch /robots.txt. Plain text means it exists; an HTML error page means it does not.
- Confirm it declares your sitemap and does not contain a bare Disallow: /.
- Fetch /sitemap.xml and count the entries against your expectation.
- Load three entries at random. All three should return the page, not a redirect.
Common Mistakes to Avoid
These are the five failures that show up again and again when a site owner writes a robots file once and never looks at it again. Each one is easy to make, cheap to fix, and expensive to leave.
- Blocking the whole site with a stray slash. A single
Disallow: /underUser-agent: *tells every crawler to leave. Sites do this while testing, then forget, and traffic disappears over weeks rather than hours, which makes the cause hard to spot. Fix: remove the line, confirm with a live fetch, and re-test in Search Console the same day. - Blocking CSS and JavaScript. Google renders pages to judge layout and content. If the stylesheet is disallowed, the rendered page looks broken, and mobile-first evaluation suffers even though nothing is wrong with the site. Fix: allow
/css/and/js/, and block only genuinely private paths. - Listing redirected and noindexed URLs in the sitemap. Every entry you promise should be a real, canonical, indexable page. Listing a 301 or a page tagged noindex sends a contradictory signal and wastes crawl budget. Fix: generate the sitemap from the same source of truth that renders the pages, not by hand.
- Using robots.txt to hide pages from search. Blocking a URL stops crawling, not indexing. The page can still appear in results as a bare link, and because Google never reads the noindex on a blocked page, the tag will not remove it either. Fix: use
noindexfor removal, and reserve robots.txt for crawl control. - Setting a sitemap path in robots.txt that 404s. The Sitemap line is a pointer, and a broken pointer is worse than none. Search Console reports the submission as a failure and you lose the discovery shortcut entirely. Fix: test the exact URL you declare, and keep it in one canonical form with no query string.
The pattern behind all five is the same: robots.txt and sitemap.xml are treated as setup tasks rather than maintenance. They describe the shape of the site, so whenever the shape changes, they change too. Put a five-minute review in the calendar once a quarter, and after any migration.
Blocked versus noindexed, side by side
| Goal | Right tool |
|---|---|
| Stop a page being crawled at all | robots.txt Disallow |
| Remove a page from search results | noindex meta tag, page must stay crawlable |
| Keep a staging copy out of the index | password protection or noindex, not robots.txt |
| Hide a PDF that ranks | noindex header X-Robots-Tag |
| Speed up crawling of useful pages | robots.txt plus a clean internal link structure |
If you are unsure which of the two you need, ask whether the page should ever appear in results. If the answer is never, you want noindex and you want Google to be able to read it.
Check it yourself: run the meta checker, or open the understanding your score. Both are free and need no sign-up.
Frequently asked
Does a sitemap guarantee indexing?
No. It guarantees discovery. Whether a page is indexed depends on quality, duplication and crawl budget.
Should I block admin pages in robots.txt?
If they are behind a login, they are not indexable anyway. Blocking them saves crawl budget but is not a security measure.
Why does my sitemap show more pages than I have?
Usually variants: http and https, with and without www, or pagination. List only canonical URLs.
Can a sitemap hurt me?
Only if it lists bad URLs such as redirects, 404s or noindexed pages. A clean sitemap is never harmful.
My sitemap is valid but Google ignored it. Why?
Validation only proves the XML parses. Google still chooses what to crawl. If the sitemap lists fifty near-identical pages, most will sit unvisited. Improve the pages and the crawl follows.
Should I delete an old sitemap after a redesign?
Yes, once its URLs return 404 or 301. Keeping a stale sitemap alive keeps old addresses in Google's queue and makes the indexing report look worse than the site really is. Remove it and submit the new one.
Written by Anthony Bailey · Anthony Bailey is a publisher, retired professor and computer technologist. He writes the guides on Website Checkmate and has spent his career explaining technical subjects to people who never signed up to be technical.
CHECK MY WEBSITE