Every well-behaved crawler, from Googlebot to AI bots, checks a site's robots.txt file before crawling it. The file lives at the root of the domain, such as https://example.com/robots.txt, and contains rules about which paths each crawler may visit.
A simple robots.txt
User-agent: *
Disallow: /admin/
Disallow: /cart/
Sitemap: https://example.com/sitemap.xmlThis tells every crawler (*) not to crawl the /admin/ and /cart/ sections, and points them to the sitemap.
The main directives
| Directive | What it does |
|---|---|
User-agent | Which crawler the following rules apply to (* means all) |
Disallow | A path the crawler shouldn't visit |
Allow | An exception inside a disallowed path |
Sitemap | The full URL of an XML sitemap |
Google also supports two wildcards: * matches any sequence of characters, and $ marks the end of a URL. For example, Disallow: /*.pdf$ blocks every PDF.
How Google reads the rules
- Each crawler follows the most specific group that names it. If there's a
User-agent: Googlebotgroup, Googlebot ignores the*group entirely. - Within a group, the most specific rule wins: the one with the longest matching path.
- If an Allow and a Disallow match equally, Allow wins.
- Paths are case-sensitive.
- If robots.txt returns a 404, Google assumes it can crawl everything. If it returns a server error for a long time, Google may stop crawling the site.