robots.txt gives cooperative crawlers instructions about which URL paths they may crawl. It is not authentication, a privacy control or a reliable way to remove indexed URLs. Use it carefully and test crawler-specific behavior.
What robots.txt Does (and Doesn't Do)
robots.txt controls crawling, not indexing. This is the most misunderstood aspect of robots.txt and the source of most mistakes.
- Crawling = a search engine bot visiting and downloading a page's content.
- Indexing = a search engine adding a page to its search results database.
When you block a URL via robots.txt, you prevent the bot from reading the page. But if other websites link to that page, Google may still index the URL — it just won't have any content to show, resulting in a listing that says "No information is available for this page." To truly prevent indexing, use a noindex robots meta tag on the page itself.
Critical rule: If you want a page to be noindexed, do NOT block it in robots.txt. The bot must be able to crawl the page to see the noindex directive.
robots.txt Syntax
The file uses a simple directive-based syntax. Here are the core directives:
| Directive | Purpose | Example |
|---|---|---|
User-agent | Specifies which bot the rules apply to | User-agent: Googlebot |
Disallow | Blocks a path from being crawled | Disallow: /admin/ |
Allow | Overrides a Disallow for a specific sub-path | Allow: /admin/public/ |
Sitemap | Points to an XML sitemap | Sitemap: https://example.com/sitemap.xml |
Crawl-delay | Seconds between requests (Bing respects, Google ignores) | Crawl-delay: 10 |
Wildcard patterns: Use * to match any sequence of characters and $ to match the end of a URL. For example, Disallow: /*.pdf$ blocks all PDF files across your entire site.
User-Agent Targeting
You can create different rule sets for different bots. Common user agents include:
*— matches all crawlers (the wildcard default).Googlebot— Google's primary web crawler.Bingbot— Microsoft Bing's crawler.Googlebot-Image— Google's image crawler (block to prevent image indexing).GPTBot— OpenAI's crawler for AI training data.CCBot— Common Crawl's bot, often blocked by sites that don't want AI training scraping.
Google selects the most specific matching user-agent group and combines groups matching that same agent. A specific group does not inherit the wildcard group. Other crawlers may differ; test the intended crawler’s documented parsing rules.
Common robots.txt Examples
Allow everything (default if no robots.txt exists):
User-agent: *
Disallow:
Block a single directory:
User-agent: *
Disallow: /admin/
Disallow: /staging/
Block everything except one directory:
User-agent: *
Disallow: /
Allow: /public/
Block AI crawlers while allowing search engines:
User-agent: GPTBot
Disallow: /
User-agent: CCBot
Disallow: /
User-agent: *
Disallow: /admin/
Sitemap: https://example.com/sitemap.xml
Crawl Budget Optimization
Crawl budget matters primarily for very large sites (Google's guidance targets roughly 1 million+ pages, or 10,000+ pages that change daily). For smaller sites, Google generally crawls everything without issues. But for large sites, wasting crawl budget on low-value pages means important pages get crawled less frequently.
Pages to consider blocking:
- Faceted navigation — filtering URLs like
/shoes?color=red&size=10&sort=pricecan create millions of near-duplicate pages. - Internal search results —
/search?q=pages generate infinite URL combinations. - Session/parameter URLs — URLs with session IDs, tracking parameters, or pagination beyond reasonable depth.
- Print/PDF versions — duplicate content in alternative formats.
- Protect private staging environments with authentication or network access controls. robots.txt is public and does not prevent access or guarantee exclusion from indexing.
Blocking vs Noindexing: When to Use Which
| Scenario | Use robots.txt? | Use noindex? | Why |
|---|---|---|---|
| Private admin area | Optional crawl control | Not a confidentiality control | Require authentication; robots.txt and noindex do not secure private content |
| Thin content pages you want de-indexed | No | Yes | Bot must see the noindex directive |
| Infinite faceted navigation | Yes | Optional | Preserves crawl budget at scale |
| Pages with sensitive information | No | No | Use authentication — robots.txt is public |
| Duplicate content with canonical tag | No | No | Let bot crawl, read canonical, and consolidate |
Testing Your robots.txt
Always validate your robots.txt before deploying changes to production. A single syntax error can accidentally block your entire site.
- Google Search Console — the robots.txt report shows files Google fetched and parsing information. URL Inspection’s indexed view describes the last indexed version; use the live test for current fetchability and inspect its reported crawl allowance. Neither view guarantees future indexing or instantaneous use of a newly deployed robots.txt file.
- Manual testing — visit
yourdomain.com/robots.txtin a browser and visually inspect the output. Confirm you can see the file, it returns a 200 status code, and the content-type istext/plain. - Staging first: Test rule changes before deployment and verify the live result. An accidental crawl block can disrupt crawling, but does not necessarily remove already indexed URLs or do so within a fixed time.
robots.txt & International Sites
For sites with multiple subdomains or country-code paths, keep these considerations in mind:
- Each subdomain requires its own robots.txt —
blog.example.com/robots.txtandshop.example.com/robots.txtare completely independent files. - Subdirectory-based internationalization (
/en/,/fr/,/de/) shares a single root robots.txt. Define rules per path prefix:Disallow: /fr/admin/. - Include sitemap references for all language versions to ensure comprehensive crawling of international content.
Common Mistakes
- Blocking all crawling:
Disallow: /in an applicable group can prevent cooperative crawling, but does not hide the site from all search results or protect access. Check deployment rules and use authentication for private content. - Blocking CSS and JavaScript — Google needs to render pages to understand them. Blocking CSS/JS files prevents rendering, which hurts both indexing and rankings.
- Using robots.txt for security — robots.txt is publicly readable. Anyone can visit
/robots.txtto see exactly which paths you're "hiding." Never rely on it for security. - Conflicting with noindex — blocking a page in robots.txt AND adding noindex to it means the bot can't reach the page to see the noindex tag. The page might still get indexed via external links.
- Forgetting the trailing slash —
Disallow: /directoryblocks both/directoryand/directory-other/. Add a trailing slash (Disallow: /directory/) to be more precise. - Not including a Sitemap directive — while not required, pointing to your sitemap in robots.txt ensures crawlers can find it even if it's not submitted in Search Console.
Try It Yourself
Build a properly formatted robots.txt file with user-agent targeting, disallow rules, allow overrides, and sitemap references — ready to deploy.
robots.txt Generator →