Syntax: User-agent, Disallow, Allow, Sitemap, and wildcards
The file always lives in the same spot: the root of the domain, reachable at https://yourdomain.com/robots.txt. A crawler that follows the rules checks it before requesting any other URL on the site, so it needs to be reachable without redirects or blocks standing in front of it.
Each rule block starts with User-agent, which names the crawler the following lines apply to: a specific name like Googlebot, or an asterisk to target all of them. The actual directives come next. Disallow blocks a path or an entire directory; an empty line after Disallow, with no path after it, blocks nothing at all. Allow does the opposite and mostly serves to carve out an exception inside a blocked directory, a single file that should still get crawled even though its folder is closed off. The optional Sitemap directive, with the sitemap's full URL, tells the crawler where to find it, and it can appear more than once if there are several sitemaps.
Two wildcards extend what a few lines can express: the asterisk (*) stands in for any sequence of characters within a path, and the dollar sign ($) marks the exact end of a URL. Combined, they can block, say, every URL ending in a specific parameter without listing each one individually.
User-agent: *
Disallow: /admin/
Disallow: /cart/
Disallow: /*?filter=
Allow: /wp-content/uploads/
User-agent: Googlebot-Image
Disallow: /private-photos/
Sitemap: https://yourdomain.com/sitemap.xml
When several rules in the same block apply to the same URL, Google follows the more specific one, the one with the longer path, not whichever rule appears first in the file. That's why a narrow Allow can sit next to a broader Disallow in the same block without contradicting it.
Disallow and Allow paths are case-sensitive, so /Admin/ and /admin/ read as two different rules to a crawler even if the server maps them to the same folder underneath. Lines starting with a hash (#) are comments, and the crawler skips them entirely, useful for noting why a particular rule exists without changing what the file actually does.
