robots.txt and sitemap: the two files you use to talk to crawlers
SEOWhat robots.txt may block and what it must not, why a block does not keep a page out of the index, what belongs in the sitemap and how to check both files yourself in a few minutes.
11 min read
By Timo Wessels Published
robots.txt and the XML sitemap are two files that address machines only. The robots.txt tells crawlers which addresses they should not fetch. The sitemap tells them the reverse: which addresses you consider important. No visitor ever sees them. Even so, they are regularly the spot where an otherwise clean website loses visibility: through a block that blocks too much, or a sitemap that says something different from the pages themselves.
The most important points first:
- The
robots.txttells crawlers what they should not fetch. Crawlers are the search robots of search engines. - The sitemap, the list of your pages, tells them what you consider important.
- Visitors never see either file, but a wrong one costs visibility.
What the robots.txt does and what it does not
The robots.txt controls which addresses a crawler may fetch. Google names the main purpose as not overloading the website with requests. It is explicitly not a means of keeping a page out of Google.
Three misunderstandings that follow:
- Blocked does not mean invisible. A blocked page can still appear in search results if other pages point to it. Then the address is there, but without a description.
- Blocked does not mean protected. The standard (RFC 9309) itself says: the rules are not a form of access authorisation. What is confidential belongs behind a password.
- Blocked and
noindexexclude each other. Google writes: fornoindexto work, the page must not be blocked by therobots.txt. Otherwise the crawler never sees the instruction. Whoever wants something out of the index setsnoindexand allows fetching.noindexin therobots.txtitself has not been honoured by Google since 1 September 2019.
What is sensibly blocked: the admin area, internal search results and filter combinations that produce any number of addresses. So everything that keeps crawlers busy without finding anything sensible. That is my assessment.
What does not belong in the robots.txt: the test environment. A blocked staging site can still turn up if others point to it. For development environments WordPress recommends the header X-Robots-Tag: noindex, nofollow for all files. Google names password protection as a way of keeping content out of the index. Safest is both.
CSS and JavaScript
The most expensive mistake in the robots.txt is often not a blocked page but a blocked resource. Google allows blocking unimportant image, script or style files if the page is not significantly affected without them. What Google needs to display and understand the page must stay fetchable.
In WordPress that means in practice: lines such as Disallow: /wp-content/ or Disallow: /wp-includes/ have no business in the robots.txt. Stylesheets, scripts and images are there.
The rules by which Google reads the file
- One file per host, protocol and port. The
robots.txtathttps://example.com/does not apply tohttps://www.example.com/or tohttp://example.com/. It must be in the top-level directory. - For paths, upper and lower case count. The value of a
Disallowline distinguishes/Contactfrom/contact. - The most specific rule wins. If
AllowandDisallowmatch the same address, the one with the longer path applies. In a conflict Google takes the less restrictive rule. - No matching rule means allowed. If nothing stands in the file for a crawler, it may fetch everything.
- At most 500 KiB. What goes beyond is ignored.
- Google caches the file for up to 24 hours. Changes therefore do not take effect at once.
- If the file is missing (status 404), there are no restrictions. If the server answers with a 5xx error, Google first stops crawling for 12 hours and then uses the last good version for up to 30 days.
- Redirects: Google follows at least five redirects and then treats the file like a 404.
- Google does not know
crawl-delay. Other search engines partly do. - The
Sitemap:line needs a full address with protocol and domain.
A lean robots.txt for a WordPress website looks like this. This is exactly what WordPress generates by itself:
User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Sitemap: https://example.com/wp-sitemap.xml
robots.txt and AI crawlers
The robots.txt now also decides which AI systems read your content. The providers separate by purpose, and each crawler is controlled by its own name:
| Crawler | Provider | Purpose |
|---|---|---|
GPTBot |
OpenAI | Material for training the models |
OAI-SearchBot |
OpenAI | Search function in ChatGPT |
Google-Extended |
Control for training and answers in Google’s AI systems | |
Googlebot |
Google Search including the AI Overviews |
Two points where it often goes wrong:
- OpenAI writes that sites that opt out of
OAI-SearchBotdo not appear in ChatGPT search answers. Whoever only wants to prevent training blocksGPTBotand allowsOAI-SearchBot. Google-Extendedhas no user agent string of its own when fetching. It is a keyword in therobots.txtwith which you control whether content is used for training and answers in Google’s AI systems. The AI Overviews in search depend on the normalGooglebot. Whoever blocksGooglebotdisappears from search and from the AI Overviews at the same time. That is rarely the intention.
If nothing is in your robots.txt for an AI crawler, it may fetch everything. That is also a decision, even if nobody made it consciously. More on which crawlers you need for AI answers is in the article on AI visibility.
The sitemap: when you need one
A sitemap is a list of the addresses you consider important. Google names cases in which it helps especially:
- large websites, because it is harder there to make sure every page is linked,
- new websites with few links from outside,
- websites with a lot of video, images or news.
You may not need one if the website is small. Google means about 500 pages or fewer. A sitemap does no harm there, though, and WordPress generates one anyway. It is never a guarantee: Google writes explicitly that it does not guarantee that every address is fetched and indexed.
What belongs in the sitemap
Only canonical, indexable addresses with a value of their own. No redirects, no error pages, nothing with noindex, nothing with a canonical to another page. Google calls inclusion in a sitemap a weak signal that an address is the authoritative one. If the sitemap contradicts the pages, it weakens exactly this signal. Google also advises not to give a different address in the sitemap than in the canonical for the same page.
The most common finding is therefore not a lack but a contradiction: the sitemap lists addresses that are set to noindex or redirect. The website then says at the same time “here is an important page” and “please do not include”. Or the reverse: pages that really exist are missing because they belong to a content type the SEO plugin does not cover. That is my experience.
The formal rules:
- at most 50,000 addresses and 50 MB uncompressed per file. Beyond that it is split and joined through an index file.
- full, absolute addresses, with protocol and domain.
- UTF-8 as character encoding.
lastmodonly if it is true. Google uses the modification date only if it is consistently and verifiably accurate. What is meant is the time of the last significant update of the page, not the year in the footer.priorityandchangefreqare ignored by Google. Maintaining them is not worth it.
WordPress: robots.txt and sitemap
WordPress generates the robots.txt itself when the request reaches WordPress. It is extended through the robots_txt filter or the SEO plugin. If a real file sits in the root directory, the web server, in my experience, delivers it directly and WordPress does not come into play at all. Then changes in the plugin have no effect. That is a typical cause of “but I changed it”.
WordPress has brought a sitemap of its own since version 5.5, at /wp-sitemap.xml. It is an index file whose sub-files by default have at most 2,000 entries, and WordPress points to it in the robots.txt. SEO plugins usually replace it with one of their own. If “Discourage search engines from indexing this site” is enabled, WordPress switches the sitemap off.
How to check it yourself
Look at the robots.txt. Open yourdomain.com/robots.txt in the browser. The file should be short and readable. Watch for three things:
- Does
Disallow: /stand anywhere without further restriction? That blocks the whole website. - Do
wp-content,wp-includes,.cssor.jsappear in aDisallowline? - Is there a
Sitemap:line, and does the address in it work?
Open the sitemap. Open the address named. An error message or an empty file means: the entry is out of date. Spot check: open five addresses from the sitemap. If one redirects or carries noindex, the sitemap has a problem.
Search Console. In the “Sitemaps” report you see whether the file was submitted and read without errors and how many addresses Google found in it. In the page indexing report you can filter by the addresses of a submitted sitemap and see how many of them are actually indexed. A large gap between the two numbers is the interesting finding, and the reasons stand right beside it, such as that the address is blocked by the robots.txt.
The AI crawlers. Search your robots.txt for GPTBot, OAI-SearchBot and Google-Extended and for the crawlers of further providers that the article on AI visibility lists. If nothing is there, they are allowed.
The service in front. If the website runs behind a CDN or a firewall, a crawler can be turned away there although the robots.txt allows it. A look at its settings belongs to the check.
What you can do
- Check whether a real
robots.txtis in the root directory, and decide: either maintain the file or delete it and let WordPress or the SEO plugin take over. Not both. - Take out blocks for CSS, JavaScript and images as far as the page needs them to display. Leave the admin area, internal search and filter parameters blocked.
- Put nothing in the
robots.txtthat should really be out of the index.noindexis for that. - Enter the sitemap in the
robots.txtand also submit it in Search Console. - Make sure sitemap and pages say the same: what is set to
noindex, redirects or carries a foreign canonical does not belong in it. - Make a conscious decision on the AI crawlers. For most service provider websites it is: allow search crawlers, training according to your own stance. Whoever wants to appear in AI answers must be readable.
- After every relaunch: look at
robots.txtand sitemap first. A block from the test environment or a sitemap full of old addresses otherwise only shows weeks later. That is my experience.
Sources
- Google Search Central, Introduction to robots.txt — purpose, no means against indexing, blocked pages without a description, resources: developers.google.com(external site: developers.google.com)
- Google Search Central, How Google interprets the robots.txt specification — host and protocol, 500 KiB, 24 hours, 4xx and 5xx, precedence of rules,
crawl-delay,Sitemap:line, redirects: developers.google.com(external site: developers.google.com) - IETF, RFC 9309: Robots Exclusion Protocol — no matching rule means allowed, no access control: rfc-editor.org(external site: rfc-editor.org)
- Google Search Central Blog, A note on unsupported rules in robots.txt —
noindexin the robots.txt no longer honoured since 1 September 2019, password protection: developers.google.com(external site: developers.google.com) - Google Search Central, Block Search indexing with noindex — noindex only works without a robots.txt block: developers.google.com(external site: developers.google.com)
- WordPress Core, Changes to prevent search engines indexing sites —
X-Robots-Tag: noindex, nofollowfor development environments: make.wordpress.org(external site: make.wordpress.org) - OpenAI, Overview of OpenAI Crawlers — GPTBot for training, OAI-SearchBot for search in ChatGPT: developers.openai.com(external site: developers.openai.com)
- Google, Google’s common crawlers — Google-Extended as a keyword in the robots.txt: developers.google.com(external site: developers.google.com)
- Google Search Central, AI features and your website — Googlebot and robots.txt as the control for search: developers.google.com(external site: developers.google.com)
- Google Search Central, What is a sitemap — about 500 pages, new websites, media, no guarantee: developers.google.com(external site: developers.google.com)
- Google Search Central, Build and submit a sitemap — 50,000 addresses and 50 MB, absolute addresses, UTF-8,
lastmod,priorityandchangefreq: developers.google.com(external site: developers.google.com) - Google Search Central, What is URL canonicalization — sitemap as a weak canonical signal: developers.google.com(external site: developers.google.com)
- Search Console Help, Sitemaps report — status, addresses found: support.google.com(external site: support.google.com)
- Search Console Help, Page indexing report — reasons for non-indexed addresses, filter by sitemap: support.google.com(external site: support.google.com)
- WordPress Developer Resources, do_robots() — default content of the robots.txt generated by WordPress: developer.wordpress.org(external site: developer.wordpress.org)
- WordPress Core, New XML Sitemaps Functionality in WordPress 5.5 —
/wp-sitemap.xml, 2,000 entries, entry in the robots.txt, switched off when visibility is discouraged: make.wordpress.org(external site: make.wordpress.org) - Own practice — a real file in the root directory and the plugin, contradictions between sitemap and pages, the check after the relaunch.