GUIDE

robots.txt and XML Sitemaps: What They Do and How to Get Them Right

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:

That is it. Allow everything, declare the sitemap, stop.

The mistakes that cost real traffic

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

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

  1. 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.
  2. Read it for Disallow: / with nothing after it. That blocks everything.
  3. Open yourdomain.com/sitemap.xml. It should start with an XML declaration and contain <urlset>.
  4. Pick three URLs from the sitemap at random and load them. All three should return the page, not a redirect or an error.
  5. 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

  1. Fetch /robots.txt. Plain text means it exists; an HTML error page means it does not.
  2. Confirm it declares your sitemap and does not contain a bare Disallow: /.
  3. Fetch /sitemap.xml and count the entries against your expectation.
  4. 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.

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

GoalRight tool
Stop a page being crawled at allrobots.txt Disallow
Remove a page from search resultsnoindex meta tag, page must stay crawlable
Keep a staging copy out of the indexpassword protection or noindex, not robots.txt
Hide a PDF that ranksnoindex header X-Robots-Tag
Speed up crawling of useful pagesrobots.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.

Run the checks yourself. The free audit scores your page on 24 tests and tells you what to fix: check any website. For one specific problem, the link checker, speed test, meta checker and security checker each go deeper on their own.

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.