What a robots.txt file actually tells a crawler
A robots.txt file sits at the root of a domain — example.com/robots.txt — and tells well-behaved crawlers which paths they may fetch. It is a request, not an enforcement mechanism: nothing stops a crawler from ignoring it, and it does nothing to hide a page that's already indexed. Once you know those two limits, the syntax itself is almost trivial.
The method
- Start with a user-agent line:
User-agent: *applies the rules that follow to every crawler; naming a specific one (User-agent: Googlebot) applies them only to that bot. - Add
Allow:orDisallow:lines under that user-agent block.Disallow: /blocks the entire site;Disallow: /adminblocks only paths starting with/admin; an emptyDisallow:blocks nothing. - Longest-match wins when rules conflict. If
Disallow: /blogandAllow: /blog/publicboth exist, a crawler checks which matched path is longer —/blog/publicis longer than/blog, so that one page is allowed even though its parent folder is blocked. - Add a
Sitemap:line (full URL, not a relative path) so crawlers that respect it know where to find your full URL list. - Remember what this file can't do: a disallowed page can still get indexed if something else links to it, just without a crawled description. To truly keep a page out of search results, use a
noindexmeta tag or require a login — robots.txt only asks crawlers not to request the page, it doesn't hide it.
A worked example
A site wants crawlers to index everything except its admin area and shopping cart, and wants to point them at its sitemap:
User-agent: *
Allow: /
Disallow: /admin
Disallow: /cart
Sitemap: https://example.com/sitemap.xml
Walk the longest-match rule on three real paths:
/admin/users— matchesDisallow: /admin(the rule path/adminis 6 characters) andAllow: /(1 character). The longer match wins, so this path is blocked./cart/checkout— matchesDisallow: /cart(rule path/cartis 5 characters) againstAllow: /(1 character); blocked./blog/post-1— matches onlyAllow: /; nothing disallows it, so it's fetchable.
Nowhere in that file is there a way to make /admin/users disappear from search results if it's already indexed and linked from elsewhere — that's a separate job for a noindex tag on the page itself.
Where people get it wrong
Two mistakes show up constantly. First, treating a blocked path as hidden: a URL can appear in search results with no snippet ("No information is available for this page") because Google saw a link to it without ever being allowed to crawl its content. Second, putting the file somewhere other than the domain root — example.com/blog/robots.txt is never read; it must live at example.com/robots.txt.
The robots.txt generator builds the file from a allow-all, block-all, or allow-with-exceptions choice, so the syntax is never the part you get wrong — only the strategy is left to you.