Skip to content
ع
SEO

robots.txt and XML Sitemaps: Guiding Search Engines Without Blocking Your Pages by Mistake

One wrong line in robots.txt can hide your whole site from Google. A guide to understanding the file, the sitemap and when to use each tool.

Ahmad Khreiswebmaster5.0(2)
Published Updated 11 min read
Illustration for the article: Robots.txt and XML Sitemaps: A Practical Guide to Guiding Search Crawlers

A robots.txt file is a small text file at the root of your site that tells crawlers which parts they may visit, while an XML sitemap is a list of the pages you want search engines to know about. Both are simple, but mistakes are costly: one line can block your whole site, and a sitemap full of stale URLs wastes crawl time. This guide explains when to use each one and how to write it correctly.

Key takeaways

  1. 1robots.txt controls crawling, not whether a page appears in results.
  2. 2To keep a page out of results use noindex, and don't block it in robots.txt at the same time.
  3. 3A sitemap lists only important, indexable pages.
  4. 4Reference the sitemap in robots.txt and submit it in Search Console.

What's the difference between robots.txt, noindex and a sitemap?

Mixing up these three tools is the root of most problems. Each answers a different question:

ToolAnswers the questionExample use
robots.txtMay the crawler visit this path?Stopping crawls of internal search results and the cart
noindex tagShould this page appear in results?Thank-you pages after a form submission
XML sitemapWhich important pages should you know about?Service pages, articles and products

1. How does a crawler read your site?

Before visiting any page, a crawler opens robots.txt at the domain root to learn what's allowed and what isn't. Here's an example for a service business:

What may be crawled and what's blocked

example.com
  1. Allowed: public pages
    • Services
    • Blog
    • Tools
  2. Blocked: no value to searchers
    • /admin dashboard
    • /search internal results
Illustrative example. Public pages are open to crawling; the dashboard and internal search results are blocked because they don't help searchers.

In the file that's a few simple lines: User-agent: *, then Disallow: /admin and Disallow: /search, then a Sitemap: line with the sitemap's full URL.

2. The mistake that blocks a whole site

The most dangerous line in this file is very short: Disallow: /, which blocks crawling of the entire site. It happens often when a site moves from staging to production and the developer forgets to remove the block:

3. noindex and robots.txt don't mix

To hide a page from results, put a noindex tag on it and let the crawler reach it. If you block it in robots.txt, the crawler never sees the tag, and the page may stay in results by its URL if other sites link to it:

The wrong way

  • Block the page in robots.txt
  • And add noindex to it
  • The crawler never sees the tag, so it isn't applied

The right way

  • Allow the page to be crawled
  • And put noindex in its head
  • The crawler reads the tag and drops it from results

4. A clean XML sitemap

A sitemap isn't a list of every URL, but of the pages you want in results. Per Google's documentation, one file holds up to 50,000 URLs or 50 MB uncompressed, and Google ignores priority and changefreq while using lastmod when it's accurate. To make the sitemap useful:

  1. 1
    Include final URLs only

    Pages returning 200 whose canonical points to themselves.

  2. 2
    Exclude what shouldn't be indexed

    noindex, redirected and duplicate pages.

  3. 3
    Keep lastmod honest

    Update it only when the content really changes.

  4. 4
    Reference it in robots.txt

    With a Sitemap line and its full URL.

  5. 5
    Submit it in Search Console

    And watch discovered versus indexed counts.

To organise which pages deserve to appear at all, read our technical SEO guide and internal linking guide, and check your pages with the Website SEO Checker.

Conclusion

robots.txt decides where search engines crawl, noindex decides what appears in results, and the sitemap introduces your important pages. Don't mix them up, check the file after every launch, and keep the sitemap clean and accurate. If you'd like a full technical review of your site, see our SEO and digital marketing service.

Frequently asked questions

Does robots.txt stop a page appearing in Google?

Not necessarily. It blocks crawling, not indexing; a blocked page can still appear by its URL if other sites link to it. To keep it out, use a noindex tag on a page that can be crawled.

Where does robots.txt go?

At the very root of the domain, such as example.com/robots.txt. Each subdomain has its own file.

How many URLs can a sitemap hold?

Per Google's documentation: up to 50,000 URLs or 50 MB uncompressed per file; beyond that, split it and use a sitemap index file.

Does Google use priority and changefreq?

Google says it ignores priority and changefreq, and uses lastmod when it's consistently accurate.

Sources & references

  1. Google Search Central — Introduction to robots.txt
  2. Google Search Central — Build and submit a sitemap
  3. RFC 9309 — Robots Exclusion Protocol
  4. sitemaps.org — Sitemaps XML format
Ahmad Khreis

About the author

webmaster

I believe technology is useful when it solves a clear problem — not when it's adopted because it's trendy. AI is a powerful tool for speeding up research, writing, analysis and automation, but it needs human expertise to review, guide and verify accuracy. That's why I prefer to start by understanding the business and its goals, then choose the simplest solution that delivers a measurable result, and build audience trust with honest, useful content.

Reader rating
5.0(2)
Published articles
81
  • #robots.txt
  • #sitemap
  • #technical seo
  • #crawling
Share

How would you rate this article?

Be the first to rate

Comments

No comments yet. Share your thoughts!

Leave a comment

Related articles