Chapter 1: What robots.txt does, and what it doesn’t
It controls crawling, not indexing.
A robots.txt file sits at the root of a host and tells crawlers which paths they may fetch. It is read in groups: each starts with one or more User-agent lines, and a crawler obeys only the group that names it, falling back to User-agent: * when none does. The rules are defined in RFC 9309 (opens in a new tab): the longest matching rule wins, and on a tie Allow beats Disallow.
It doesn’t keep a page out of search. Google says (opens in a new tab) it can’t index the content of a disallowed page but may still index the URL and show it without a snippet. And each host needs its own file: the one on example.com doesn’t cover shop.example.com. The lesson on writing robots.txt rules for AI crawlers walks through a pattern most sites want.