SEO
robots.txt: what it is, how to write it and how to check it
The essentials
- robots.txt tells bots which paths they may crawl. It always lives at the root:
yoursite.com/robots.txt. - Blocking a path does not remove it from Google. That is what
noindexis for, and the bot must be able to read the page to see it. - A robots.txt that returns a server error makes search engines treat the whole site as blocked.
- Declare your sitemap there: it is the most direct way for every bot to find it.
How it works
Before crawling a site, a well-behaved bot requests /robots.txt and looks for the group of rules that applies to it. Each group starts with one or more User-agent lines followed by its rules.
| Line | What it does |
|---|---|
| User-agent | Names the bot the group applies to. * applies to every bot without a group of its own. |
| Disallow | A path the bot should not crawl. Disallow: / closes the whole site; empty closes nothing. |
| Allow | An exception inside a closed path. The most specific (longest) rule wins. |
| Sitemap | Full address of the sitemap. It sits outside the groups and can repeat. |
A bot only follows the most specific group that names it. If Googlebot has its own group, the User-agent: * rules no longer apply to it.
Two wildcards work in paths: * matches any sequence of characters and $ marks the end of the address. Disallow: /*.pdf$ closes every PDF.
Blocking is not deindexing
This is the most expensive mistake. Disallow stops the bot from reading the page, but Google can still index the address if other sites link to it: it shows up in results with no description.
- To remove a page from results, let it be crawled and give it
<meta name="robots" content="noindex">. - If you block it in robots.txt, the bot never sees the
noindexand the page can stay indexed. - For truly private content, the protection is a password, not robots.txt: the file is public and anyone can read which paths you hide.
A base robots.txt
Most sites need little: close the areas that add nothing to search (admin, cart, internal search results) and declare the sitemap.
User-agent: * Disallow: /admin/ Disallow: /cart/ Sitemap: https://yoursite.com/sitemap.xml
To decide what to do with AI bots, read How to allow AI crawlers in robots.txt: there are search bots and training bots, and they are worth treating differently.
How to check it
- Open
yoursite.com/robots.txt. It should return a 200 status and plain text, not an HTML page. - Make sure no important page falls under a
Disallow: the SEO Army robots.txt tester checks any path against each bot. - Make sure the declared sitemap exists and responds.
- If your CMS generates the file (WordPress, Shopify), check the published result, not the settings screen.
Check it
Check your site’s robots.txt
Common mistakes
- Keeping the staging site’s
Disallow: /at launch. It closes the whole site. - Blocking CSS and JavaScript. Google needs them to see the page the way a visitor does.
- An HTML page instead of the file. It happens when the server answers with the home page or a styled 404: bots find no rules and no sitemap.
- Going over 500 KiB. Google ignores everything past that limit.