Guides · Business

How to write a robots.txt and sitemap.xml that help search engines.

A clear guide to robots.txt and XML sitemaps: syntax, what to block, what not to block, lastmod, limits and how to submit to Search Console.

Key takeaways

  • robots.txt tells crawlers which paths they may fetch. It does not remove pages from search results.
  • A sitemap lists the URLs you want indexed, to help discovery.
  • To keep a page out of search, use a noindex tag, not robots.txt.
  • Keep both files simple and accurate.

robots.txt

It lives at https://example.com/robots.txt. The simplest useful file:

User-agent: *
Allow: /

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

Block areas that should not be crawled, such as an admin area or internal search results:

User-agent: *
Disallow: /admin/
Disallow: /cart/
Sitemap: https://example.com/sitemap.xml

Important points

  • Disallow stops crawling, not indexing. A blocked URL can still appear in results if other sites link to it, without a snippet.
  • To keep something out of results, allow crawling and use <meta name="robots" content="noindex">. If the crawler cannot fetch the page, it cannot see the noindex.
  • Do not block CSS and JavaScript that the page needs to render.
  • robots.txt is public. Do not list secret paths in it.
  • It is a request, not security. Bad bots can ignore it.

sitemap.xml

A sitemap is an XML file that lists URLs:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://example.com/blog/how-to-verify-an-installer-with-sha256</loc>
    <lastmod>2026-12-06</lastmod>
  </url>
</urlset>

What to include

  • Canonical, indexable URLs that return 200.
  • The same URL form you use in canonicals (https, host, trailing slash).

What to leave out

  • Redirected URLs, 404 pages and noindex pages.
  • Duplicates and parameter variations.

lastmod

Set lastmod to the date the content last changed in a meaningful way. Google says it uses it only if it proves reliable, so do not update it for trivial edits. priority and changefreq are largely ignored.

Limits

A single sitemap can hold up to 50,000 URLs or 50 MB uncompressed. Larger sites use a sitemap index that links to several sitemap files.

Submit and monitor

  1. Add your site as a property in Google Search Console.
  2. Open Sitemaps, enter the sitemap URL and submit.
  3. Check the status for errors and the number of discovered URLs.
  4. Use the Pages report to see which URLs are indexed and why others are not.

A sitemap does not guarantee indexing. It tells crawlers where to look.

Generating it

For a handful of pages you can write it by hand. For more, generate it from the same list you use to build pages, so the files cannot drift apart. This site's sitemap is generated by a short script from the pages on disk.

Common mistakes

  • Disallowing the whole site with Disallow: / left over from development.
  • Listing noindex URLs in the sitemap.
  • Using relative URLs in <loc>. They must be absolute.
  • Forgetting the sitemap line in robots.txt.
  • Letting the sitemap list URLs that redirect.

Frequently asked questions

Do I need a sitemap for a small site?

It is not required, but it speeds up discovery, especially for new sites with few inbound links.

Should I block AI crawlers?

That is a choice for each site owner. Add specific User-agent rules for the bots you wish to restrict, and know that compliance is voluntary.

Where does llms.txt fit in?

It is a separate, optional convention to describe your site for language models. See adding an llms.txt.

See this site's own sitemap and llms.txt.

Open the sitemap