# What robots.txt is and how a well-behaved client reads it

robots.txt is the file where a site says which paths crawlers may fetch. How to find your group, which rule wins, and what to do when the file fails to load.

Canonical: https://spider.cloud/learn/robots-txt/

A robots.txt file is a plain text file at the root of a site that says which paths automated clients may fetch and which they should leave alone. A well-behaved client downloads it before any other page, finds the group of rules written for its own name, and checks each address against that group before it sends a request.

The format became a standard in September 2022, when the IETF published it as [RFC 9309](https://www.rfc-editor.org/rfc/rfc9309.html). The same document states its own limit: "These rules are not a form of access authorization." The file is a request from the site owner, and no server enforces it. Whether it gets followed is up to the client.

This page is one part of the [web scraping guide](/web-scraping/), which covers the whole subject on one page.

## Where the file lives

RFC 9309 says the rules "MUST be accessible in a file named "/robots.txt" (all lowercase) in the top-level path of the service." So `https://example.com/robots.txt` speaks for `https://example.com`, and a subdomain keeps its own file.

The file is UTF-8 text. Its own address is always open to you, because the RFC adds that "The /robots.txt URI is implicitly allowed." Reading the file never breaks a rule inside it.

## What a file looks like

```txt
User-agent: *
Disallow: /search
Allow: /search/about

User-agent: examplebot
Disallow: /drafts/
Disallow: /*.pdf$

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

Rules come in groups. A group opens with one or more `User-agent` lines and holds the `Allow` and `Disallow` lines under them. This file has two groups, one for every crawler it does not name and one for a crawler called `examplebot`.

## How to read it, step by step

This clip runs the steps on the sample file, one path at a time, and the same steps follow it in text.

How a client reads robots.txt. 1 min 10 s, no sound. The words are on screen, and the captions button shows them at your own text size.

Read the transcript

How a client reads robots.txt. A site's rules for crawlers.

Find the group that names your client. When none does, use the \* group. The file on screen reads: User-agent: \*. Disallow: /search. Allow: /search/about. User-agent: examplebot. Disallow: /drafts/. Disallow: /\*.pdf$. The client is called otherbot. No group names it, so it follows the \* group.

Compare each rule in your group with the path, starting at the first character. The client is otherbot and the path is /search/results. Disallow: /search matches. Allow: /search/about does not match. Disallow: /search is the only match, so the client does not fetch the path.

When two rules match, the longest one wins. The client is otherbot and the path is /search/about. Disallow: /search matches. Allow: /search/about matches. Allow: /search/about is the longest match, so the client may fetch the path.

A group that names your client replaces the \* group. The client is called examplebot. A group names it, so it follows that group and skips the \* group.

When no rule in your group matches, the path is allowed. The client is examplebot and the path is /search. Disallow: /drafts/ does not match. Disallow: /\*.pdf$ does not match. No rule matches, so the client may fetch the path.

When an Allow and a Disallow are the same length, use the Allow. The file on screen reads: User-agent: \*. Disallow: /search. Allow: /search. The client is otherbot and the path is /search. Disallow: /search matches. Allow: /search matches. Both are the same length, so the Allow is used and the client may fetch the path.

When the file does not load, the status code decides. 2xx: Follow its rules. 4xx: You may fetch any path. 5xx: Fetch nothing. Ask again later.

Read the full page. The page is at spider.cloud/learn/robots-txt.

1. Find your group. Compare your client's name with each `User-agent` line and ignore letter case. The RFC calls that name the product token and says it "SHOULD be a substring of the identification string that the crawler sends to the service", which is your User-Agent header. When a group names you, follow that group and skip the `*` group. When none does, follow the `*` group. When the file has neither, the RFC's answer is "no rules apply."
2. Compare the path you want with every rule in that group. A rule matches from the start of the path. Two characters are special: `*` stands for any run of characters and `$` marks the end of the path. Paths keep their letter case, so `/Drafts/` and `/drafts/` are different paths.
3. Take the longest rule that matches. In the RFC's words, "The most specific match is the match that has the most octets." In the sample, an unnamed crawler may fetch `/search/about`, because `Allow: /search/about` is longer than `Disallow: /search`. When an `Allow` and a `Disallow` are the same length, the RFC says the `Allow` should win.
4. When no rule matches, the path is allowed.

The sample has one result that is easy to get wrong. `examplebot` may fetch `/search`. Its own group says nothing about that path, and the `*` group does not apply to a crawler that has a group of its own.

## When the file does not load

What you do next depends on the status code of the request for the file.

| What came back    | What RFC 9309 says to do                                                                              |
| ----------------- | ----------------------------------------------------------------------------------------------------- |
| 2xx               | Follow the rules you can parse.                                                                       |
| A redirect        | Follow it. "The crawlers SHOULD follow at least five consecutive redirects, even across authorities". |
| 4xx               | The file is "unavailable", and the crawler may fetch any path on the site.                            |
| 5xx, or no answer | The file is "unreachable", and "the crawler MUST assume complete disallow."                           |

The last row is the strict one. A server error does not mean the site has no rules. It means you could not read them, so stop and ask again later. If the file stays unreachable for a long time, and the RFC's example is 30 days, the crawler may treat it as unavailable or keep using its cached copy.

Google reads one status its own way. Its documentation says its crawlers "treat all 4xx errors, except 429, as if a valid robots.txt file didn't exist." Treat a 429 on robots.txt the way you treat a 5xx. Wait, then ask again.

## How long to keep it

Fetch the file once per host and keep it. The RFC sets the limit: "Crawlers SHOULD NOT use the cached version for more than 24 hours, unless the robots.txt file is unreachable." One request a day per host is enough, and a client that asks before every page is making noise.

Size has a floor as well. A parser has to read at least the first 500 kibibytes of the file, and Google says it ignores what comes after that.

## Lines outside the standard

Two lines turn up in many files and are not rules in RFC 9309. The RFC allows for them: "Crawlers MAY interpret other records that are not part of the robots.txt protocol".

`Sitemap` points to a list of the site's pages. It belongs to no group, and it is a good place to start when you need to find pages.

`Crawl-delay` asks for a pause between requests. The RFC does not define it, and Google says it does not support it. Keep to it anyway. A site that writes the line has told you the pace it wants, and following it makes the job take a little longer.

## What a crawl leaves out

We ran one crawl on a practice site whose robots.txt blocks two paths. The file came back at 18:51 UTC on 2026-11-22, and it is three lines long.

```text
User-agent: *
Disallow: /lessons/
Disallow: /faq/
```

Eleven seconds later we sent this crawl. It does not set `respect_robots`, so the default applies and the crawler follows the file.

```bash
curl -s https://api.spider.cloud/crawl \
  -H "Authorization: Bearer $SPIDER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://www.scrapethissite.com/", "limit": 20, "request": "http", "return_format": "markdown"}'
```

Twenty pages came back in 6.5 seconds, each with status 200. Here they are, counted by the first part of the path. The link counts below come from the same saved run.

```text
18  /pages/
 1  /
 1  /login/
 0  /lessons/
 0  /faq/
```

The start page links to `/lessons/` under the words "Begin Lessons", and 17 of the 20 returned pages carry that same link. No address under `/lessons/` is in the list. The list does hold `/pages/forms/?page_num=22`, so the crawl followed links into the paged table and still left `/lessons/` out.

The limit was 20, so a longer crawl could list more pages. We did not send a second crawl with `respect_robots` set to false, because that would fetch paths the site asks crawlers to leave alone.

## Do this, avoid this

### Do this

- Fetch /robots.txt before the first page on each host, and again after 24 hours.
- Send a User-Agent header that names your client, and match that name against the file.
- Apply the longest rule that matches, and let Allow win a tie.
- Stop when the file returns a 5xx, and try again later.
- Keep to a Crawl-delay line when the site sets one.

### Avoid this

- Reading a server error as permission to fetch everything.
- Following the \* group when a group names your client.
- Reusing one host's file for its subdomains.
- Changing your client's name to land in a looser group.
- Treating an allowed path as a license to reuse what is on it. The file does not cover that.

## Read one yourself

This request asks the Spider API for the robots.txt of the site that publishes the RFC. It needs an API key in `SPIDER_API_KEY`.

```bash
curl -s https://api.spider.cloud/scrape \
  -H "Authorization: Bearer $SPIDER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://www.rfc-editor.org/robots.txt", "request": "http", "return_format": "raw"}'
```

The answer is a JSON array with one object, and the file is the text in its `content` field. Pick three paths on that host and work out by hand which rule wins for a crawler the file does not name.

We sent that request on 2026-11-20 at 14:17 UTC. The page status was 200, and this is the whole `content` field.

```text
User-agent: *
Disallow: /rfc/authors/
Disallow: /rfc/rerendered/
Disallow: /rfc/v3test/
Sitemap: https://www.rfc-editor.org/sitemap.xml
```

The API reference describes the `respect_robots` option as "Follow robots.txt. Default true." The request above does not set it.

A robots.txt file is not the law, and this page is not legal advice. For the rulings and statutes, read [Is web scraping legal? What 67 top sites ask for in robots.txt](/blog/is-web-scraping-legal-robots-txt-survey/). If you have not sent a request yet, start with [lesson 1 of the course](/learn/course/your-first-request/).

## Sources

1. [RFC 9309, Robots Exclusion Protocol, IETF, September 2022](https://www.rfc-editor.org/rfc/rfc9309.html) Read November 20, 2026
2. [Google Search Central, How Google interprets the robots.txt specification](https://developers.google.com/search/docs/crawling-indexing/robots/robots_txt) Read November 20, 2026
3. [Spider OpenAPI file, the respect_robots parameter and the content field](https://spider.cloud/openapi.yaml) Read November 20, 2026
