Skip to content
Future Forge ToolsWeb Tools ProOpen free tools

SEO & Marketing

Robots.txt and Sitemap.xml: How They Work Together for SEO

How robots.txt and sitemap.xml work together: one blocks crawling, one lists pages to index. Plus the Sitemap line, common conflicts and a safe setup.

Robots.txt and Sitemap.xml: How They Work Together for SEO
On this page

Robots.txt and sitemap.xml work as a pair. Robots.txt, a text file at your domain root, tells crawlers which URLs they should not crawl. Sitemap.xml lists the URLs you do want crawled and indexed. Robots.txt can also point to the sitemap with a Sitemap: line, so crawlers find both from one place.

Neither file forces a search engine to do anything, and that’s where most of the confusion starts. Getting them to agree with each other matters more than getting either one fancy. Here’s how they fit together and how to set them up safely.

Try it: Robots.txt GeneratorCreate a correct robots.txt with rules per crawler, crawl-delay, sitemap links and a one-click preset to block AI crawlers.

Open tool — free

Robots.txt vs sitemap.xml at a glance

robots.txtsitemap.xml
JobSays which paths crawlers should skipLists the pages you want found
FormatPlain text rulesXML list of URLs
LocationMust be at the root: /robots.txtAnywhere, usually /sitemap.xml
Read byCrawlers, before they crawlCrawlers, via robots.txt or a direct submission
Binding?Voluntary; well-behaved bots follow itA hint; search engines may skip pages
Controls indexing?No, only crawlingNo, only discovery
Required?No, but missing means everything is crawlableNo, but helps new and large sites

Think of robots.txt as the “staff only” signs and the sitemap as the visitor map. They should describe the same building.

How do robots.txt and sitemap.xml work together?

A crawler arriving at your site fetches /robots.txt first. It reads the rules for its user agent, notes any Sitemap: lines, then downloads the sitemap to get a list of URLs worth visiting. While crawling those URLs, it skips anything the robots.txt rules disallow.

That gives each file a clear job:

  • Robots.txt removes noise. Internal search results, cart and checkout pages, admin areas and endless filter combinations don’t need crawling.
  • The sitemap highlights what matters. Your real, canonical pages, especially new ones and ones with few internal links.
  • The Sitemap line connects them. Any crawler that respects robots.txt can find your sitemap without you submitting it to each search engine.

A robots.txt with a sitemap: the combined example

Here’s a typical file for a blog or small business site:

User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Disallow: /search/
Disallow: /cart/

Sitemap: https://example.com/sitemap.xml

Every crawler (*) skips the admin area except one file some themes need, plus internal search and the cart. The last line tells crawlers where the sitemap lives.

A few rules about that Sitemap line:

  • Use the full absolute URL, including https://. A relative path like /sitemap.xml isn’t valid there.
  • It applies to all crawlers regardless of which user-agent group it sits near, so putting it at the end is just a tidy convention.
  • You can list several sitemaps, or a single sitemap index file that points to the rest.

For a step-by-step on adding that line on different platforms, see our guide on how to add a sitemap to robots.txt. For ready-made files for WordPress, online stores and staging sites, browse our robots.txt examples.

The conflicts that cause problems

Most trouble comes from the two files disagreeing. Search Console reports these, but it’s easier to avoid them.

Sitemap lists URLs that robots.txt blocks

If a page is in your sitemap but disallowed in robots.txt, you’re asking Google to index a page it isn’t allowed to read. Either remove it from the sitemap or unblock it. Generated sitemaps from plugins sometimes include tag archives or other sections you’ve blocked, so check after any configuration change.

Using robots.txt to keep a page out of Google

Robots.txt controls crawling, not indexing. A blocked page can still appear in results, usually without a description, if other sites link to it. To keep a page out of search, use a noindex robots meta tag or an X-Robots-Tag header, and make sure the page is not blocked, or the crawler never sees the noindex. Then leave that page out of your sitemap too.

Blocking the sitemap itself

A broad rule like Disallow: /*.xml can block your own sitemap. Keep the sitemap path crawlable.

The one-line disaster

Disallow: / under User-agent: * blocks your entire site. It’s a common leftover from a staging site. A perfect sitemap can’t help if this line is live.

What belongs in the sitemap

An XML sitemap is a list of URLs, optionally with the date each page last changed. Keep it clean:

  • Include only canonical, indexable pages that return a 200 status. No redirects, no noindexed pages, no blocked URLs.
  • Keep lastmod honest. Update it only when the content really changes.
  • Don’t fuss over priority and changefreq. Google has said it ignores them, though other search engines may read them.
  • One sitemap file can hold up to 50,000 URLs. Larger sites split into several files listed in a sitemap index.

A minimal sitemap looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://example.com/</loc>
    <lastmod>2026-10-01</lastmod>
  </url>
</urlset>

WordPress already creates both

Since version 5.5, WordPress generates a basic sitemap at /wp-sitemap.xml and serves a virtual robots.txt when no real file exists. SEO plugins such as Yoast or Rank Math usually replace the sitemap with their own, often at /sitemap_index.xml, and many let you edit robots.txt from the dashboard. Uploading a physical robots.txt file overrides the virtual one.

Check which sitemap is actually live and make sure robots.txt points to that one, not a stale URL. Also confirm that “Discourage search engines from indexing this site” under Settings, Reading is unticked on a live site.

Creating both files step by step

If your platform doesn’t handle this, or you want full control, generate both files and upload them yourself.

  1. Open our free robots.txt generator. Start with the group for all crawlers and leave crawling allowed by default.
  2. Add the paths that shouldn’t be crawled, one per line, such as /cart/ or /search/. Optionally use the AI crawler preset if you want to block crawlers such as GPTBot, then review what it adds.
  3. Enter your full sitemap URL so the file includes the Sitemap line, then download it.
  4. In the XML sitemap generator, enter your base URL and paste your page paths or full URLs, one per line. Leave out anything you disallowed in step 2, then download sitemap.xml.
  5. Upload both files to your site root and open each one in a browser to confirm it loads.
  6. Submit the sitemap in Google Search Console and Bing Webmaster Tools, and recheck the reports a few days later for blocked or excluded URLs.

A safe setup to aim for

Allow crawling by default, disallow only genuinely useless URL patterns, and keep one clean sitemap of real pages that robots.txt doesn’t block. Reference that sitemap with an absolute Sitemap: line, use noindex rather than robots.txt to hide pages from search, and recheck both files whenever you change themes, plugins or site structure.

Frequently asked questions

Should the sitemap be in robots.txt?

Yes, it's a good idea. Adding a Sitemap: line with the full sitemap URL lets every crawler that reads robots.txt find your sitemap, even ones you never submit it to manually.

Does robots.txt stop a page from appearing in Google?

Not reliably. Robots.txt stops crawling, but a blocked URL can still be indexed if other pages link to it. To keep a page out of search results, allow crawling and add a noindex tag instead.

Can a sitemap include pages blocked by robots.txt?

It shouldn't. Listing a URL in the sitemap while blocking it in robots.txt sends mixed signals, and Search Console will flag those URLs as blocked.

Do I need an XML sitemap for a small website?

Not strictly, since Google can find well-linked pages on its own. A sitemap still helps new sites and pages with few internal links get discovered faster, and it costs nothing to add.

Free tools for this

admin

Writes practical guides for Future Forge Tools, where every tool runs privately in your browser.