Skip to content

SEO for websites

XML sitemaps and robots.txt: how to set up

An XML sitemap lists the pages you want indexed and robots.txt tells crawlers where not to go. See what each should contain, how to submit, common faults.

By Leous · Updated · 3 min read

Cover image for the article “XML sitemaps and robots.txt: how to set up” on the Leolinq blog

An XML sitemap is a file that lists the URLs you want search engines to index. Robots.txt is a file that tells crawlers which parts of a site they may fetch. One invites, the other restricts, and both sit at the root of the domain. This guide explains what each should contain, how to set them up and the mistakes that cause indexing problems.

What an XML sitemap is

A sitemap is an XML file, usually at /sitemap.xml, with one entry per URL:

<url>
  <loc>https://www.example.com/services/</loc>
  <lastmod>2026-11-20</lastmod>
</url>

It helps Google discover pages, especially on new sites, large sites and sites with few internal links. It is a suggestion: listing a URL does not guarantee indexing.

What a sitemap should contain

  • Only canonical URLs that return a 200 status and should be indexed.
  • No redirects, error pages, noindex pages or parameter duplicates.
  • An accurate lastmod. Google uses it when it proves reliable; priority and changefreq are ignored.
  • At most 50,000 URLs or 50 MB per file. Larger sites use a sitemap index.

Creating and submitting

  1. Generate it automatically. Most platforms and SEO plugins do. A hand-made file goes stale.
  2. Open it in a browser to confirm it loads and lists the right pages.
  3. Submit it in Search Console under Sitemaps. See Google Search Console.
  4. Reference it in robots.txt.
  5. Check the report for errors and for the gap between submitted and indexed pages.

What robots.txt is

Robots.txt is a plain text file at /robots.txt:

User-agent: *
Disallow: /cart/
Disallow: /search/

Sitemap: https://www.example.com/sitemap.xml
  • User-agent names the crawler a group of rules applies to.
  • Disallow blocks a path. Allow makes an exception.
  • Sitemap points to the sitemap.
Annotated example “Three lines you find in robots.txt”: the numbered parts are User-agent, Disallow and Sitemap
A robots.txt file usually has three kinds of lines: which crawler, which path is blocked and where the sitemap is.

Reputable crawlers follow these rules. The file is public and is not a security measure.

Robots.txt is not noindex

Robots.txt controls crawling. It does not control indexing.

  • A URL blocked in robots.txt can still be indexed if other pages link to it, shown without a description.
  • To keep a page out of the index, use a noindex tag and leave the page crawlable so Google can read the tag.
  • Blocking a page and adding noindex together defeats the purpose.
Drawing of the path Googlebot takes in two cases
Robots.txt blocks crawling; to keep a page out of Google, use noindex.

See Google indexing.

What to block

  • Cart, checkout and account pages.
  • Internal search results.
  • Filter and sort parameters with no search value.
  • Admin and API paths.
Drawing of two groups “What to block and what to leave open”
Block the parts with no search value; never block the files a page needs to render.

What not to block:

  • CSS and JavaScript that pages need to render.
  • Pages you want indexed.
  • Pages carrying a noindex you want Google to see.

Key point The sitemap says “look at these pages”. Robots.txt says “stay out of these places”. Neither replaces a noindex tag.

Robots.txt and AI crawlers

AI companies run their own crawlers with their own user-agent names, some for training and some for answering questions live. You can allow or block each one in robots.txt. Blocking the crawlers that fetch pages for answers also removes the chance of being cited there, so decide deliberately. See generative engine optimization.

Common mistakes

  • Disallow: / left over from development, blocking the whole site.
  • A sitemap full of redirects, 404s or noindex pages.
  • Blocking CSS or JavaScript.
  • Using robots.txt to hide private content.
  • A sitemap that is never updated.
  • Different rules on the www and non-www versions.

How to check

  • Open /robots.txt and /sitemap.xml in a browser.
  • Use URL Inspection in Search Console to see whether a URL is blocked.
  • Read the robots.txt report in Search Console settings.
  • Crawl the sitemap with a site crawler to find non-200 URLs.

Frequently asked questions

Does a small site need a sitemap?

It can manage without one if pages are well linked, but a sitemap costs nothing and makes reporting in Search Console clearer.

Is an HTML sitemap needed?

Not for search engines. It can help visitors on large sites.

What if there is no robots.txt?

Crawlers assume they may fetch everything. A small site with nothing to block works normally.

Both files are on the checklist for an SEO-friendly website and part of technical SEO. If you would like them checked, send your domain for a free audit.

Further reading

Official documentation and reference pages on this topic:

Keep reading More on entity, and backlinks.

Want this done for your site?

Send your domain. We reply within one working day with a first look at your site and a clear quote.

Get a free audit