robots.txt: The Complete Guide to Syntax, Rules, Wildcards, and Examples

A robots.txt file is a plain-text configuration file placed at the root of your website (https://example.com/robots.txt) that instructs search engine and AI crawlers which URL paths to request or avoid. Automated bots read robots.txt before crawling any page. The directives manage crawl budget and AI access permissions globally.

Browser Resolver Root+TLD Authoritative Website query solid = query · dashed = cached response · every hop caches until TTL
robots.txt evaluation flow: crawler fetches /robots.txt, matches User-agent group, selects longest-path rule, and evaluates access permissions

What Is a robots.txt File and What Are Its Core Directives? (Syntax Table)

Created by Martijn Koster in 1994 and standardized by the IETF in RFC 9309 in September 2022, a robots.txt file operates at the root of a domain as a UTF-8 plain-text document with a lowercase filename. Compliant web crawlers fetch /robots.txt before requesting any page on your host, parsing up to 500 KiB (512 KB) of rules organized into User-agent groups. The table below defines the 5 core directives and 2 wildcard operators.

# Group 1: Rules for all crawlers (*)
User-agent: *
Disallow: /admin/
Disallow: /api/private/
Allow: /api/public/

# Absolute URL to your XML sitemap:
Sitemap: https://example.com/sitemap-index.xml
Directive / Operator Syntax Example Supported by Google & Bing? Exact Function in Crawler Control
User-agent User-agent: Googlebot or * Yes (Required) Starts a rule group and names specific crawler tokens (or * for all bots) to which subsequent lines apply.
Disallow Disallow: /admin/ or / Yes Instructs matched crawlers not to request URL paths beginning with the specified string; empty Disallow: allows all.
Allow Allow: /admin/public.html Yes Carves out an allowed exception for specific files or subfolders inside a broader Disallow directory.
Sitemap Sitemap: https://example.com/sitemap.xml Yes Declares absolute https:// URLs of XML sitemaps; applies globally across all search engines regardless of placement.
Crawl-delay Crawl-delay: 10 Ignored by Google & Bing Requests delays in seconds between requests; honored by Yandex and select scrapers, ignored by Googlebot.
* (Wildcard) Disallow: /*.pdf$ Yes (RFC 9309) Matches zero or more sequential characters across URL paths and query strings.
$ (End Anchor) Disallow: /*.json$ Yes (RFC 9309) Anchors matches to the very end of URL paths, blocking /data.json without matching /json-guide/.

Path matching in Disallow and Allow remains strictly case-sensitive, meaning Disallow: /Admin/ fails to block /admin/. In addition, Google officially retired support for unofficial noindex: lines inside robots.txt in September 2019; search engines process only User-agent, Disallow, Allow, and Sitemap. Test syntax health directly in the robots.txt Checker and Validator.

How Do Crawlers Evaluate robots.txt Rules? (Group Precedence and Longest-Path Matching)

Search engines and AI bots do not read robots.txt from top to bottom; instead, parsers evaluate your file across 4 strict RFC 9309 matching steps where the most specific User-agent group wins and the longest path pattern takes precedence.

  1. Locate the Most Specific Group: Parsers select the single most specific User-agent block matching their crawler token and ignore all other groups. A crawler matching User-agent: Googlebot obeys only that specific group, completely ignoring rules under User-agent: * because a specific named User-agent group never merges with the wildcard * group (whereas duplicate groups sharing the exact same User-agent token are combined under RFC 9309 Section 2.2.1).
  2. Compare Candidate Paths: Parsers evaluate target URL paths against every Allow and Disallow directive inside that single matched group.
  3. Select the Longest Path Match: Parsers choose the rule with the highest character count when both Allow and Disallow match the target URL, regardless of which line appears first.
  4. Apply Allow on Tie Lengths: Parsers choose Allow as the decisive tie-breaker when matching Allow and Disallow paths share identical character lengths.
User-agent: *
Disallow: /admin/
Disallow: /checkout/

User-agent: GPTBot
Disallow: /private-docs/
# TRAP: Because GPTBot has its own specific group above, GPTBot IGNORES User-agent: *
# and crawls /admin/ and /checkout/ unless repeated under GPTBot!

Creating a dedicated User-agent block for a specific crawler such as GPTBot mandates duplicating global disallow directives into that block to preserve baseline restrictions.

5 Copy-Paste robots.txt Examples (Standard SEO, AI Split Policy, SaaS, E-Commerce, and Staging)

Five production robots.txt templates cover the 5 primary website architectures, from standard SEO and AI search visibility to e-commerce filter blocking and staging lockdowns.

  1. Modern Default (Allow Search Engines & AI Search Citations, Block AI Model Training):
    User-agent: *
    Disallow: /admin/
    Disallow: /account/
    
    # Block AI Model Training Crawlers
    User-agent: GPTBot
    User-agent: ClaudeBot
    User-agent: Google-Extended
    User-agent: Applebot-Extended
    User-agent: CCBot
    User-agent: Meta-ExternalAgent
    User-agent: Bytespider
    Disallow: /
    
    # Explicitly Allow AI Search Indexing
    User-agent: OAI-SearchBot
    User-agent: PerplexityBot
    Allow: /
    
    Sitemap: https://example.com/sitemap-index.xml
  2. SaaS & Web Application (Allow Marketing Site, Disallow App & API Routes):
    User-agent: *
    Disallow: /app/
    Disallow: /dashboard/
    Disallow: /api/
    Allow: /api/docs/
    
    Sitemap: https://example.com/sitemap.xml
  3. E-Commerce & Faceted Search (Prevent Crawl Waste on Cart & Filter Parameters):
    User-agent: *
    Disallow: /cart/
    Disallow: /checkout/
    Disallow: /*?sort=
    Disallow: /*&filter=
    Disallow: /*?q=
    
    Sitemap: https://example.com/sitemap.xml
  4. Open Documentation or Content Site (Allow Everything):
    User-agent: *
    Disallow:
    
    Sitemap: https://example.com/sitemap.xml
  5. Total Crawl Lockdown (Maintenance / Non-Public Staging):
    User-agent: *
    Disallow: /

Selecting an appropriate configuration depends on content licensing and infrastructure capacity. Web publishers implement granular controls via How to Block AI Crawlers, permit discovery using How to Allow AI Crawlers, manage Google training tokens via Google-Extended, and consult The Complete List of AI Crawlers and Bots while validating live directives in the AI Crawler Checker.

How Do Googlebot and Crawlers React to robots.txt HTTP Status Codes? (200 vs 404 vs 500)

The HTTP status code your web server returns when a crawler requests https://example.com/robots.txt directly controls whether Googlebot crawls your entire website normally or halts all crawling for up to 30 days. The table below defines how compliant crawlers handle every HTTP response status on /robots.txt under RFC 9309 and Google Search Central rules.

HTTP Status Code on /robots.txt Meaning of Status How Googlebot & Compliant Crawlers React SEO Impact on Your Website
200 OK File found and served Parses UTF-8 text up to 500 KiB and caches rules for up to 24 hours. Normal operation; crawler obeys all declared rules.
301 or 302 Redirect File redirects to another URL Follows up to 5 redirect hops to locate the target file. Safe if final destination returns 200 OK; fails on redirect loops.
404 Not Found or 410 Gone No robots.txt file exists Treats missing files as full access (Allow All). Full crawling permitted; missing files never block indexing.
401 or 403 Forbidden Access denied on /robots.txt Googlebot treats 401 and 403 as equivalent to 404 (Allow All). Putting WAF 403 blocks on /robots.txt fails open and allows crawling.
429 or 5xx (500, 503) Server error or rate limit Googlebot halts all crawling for the first 12 hours while retrying. After 12 hours, falls back to the last good cached copy (up to 30 days) or resumes crawling if no cached copy exists.

Server administrators prevent catastrophic deindexing by ensuring firewall rate limiters never return 500 or 503 errors when automated crawlers fetch /robots.txt. In addition, returning 403 Forbidden fails open under RFC 9309 specifications, removing all crawling restrictions rather than enforcing lockdown.

4 Critical SEO Mistakes to Avoid in robots.txt (Disallow vs noindex and CSS/JS Files)

Four common robots.txt misconceptions cause site owners to leave private pages indexed in Google, break mobile-first rendering, or expose hidden URLs to attackers.

  1. Using Disallow to Remove Pages from Search Results: Disallow blocks crawling, not indexing. Pages linked externally still appear in search results with the snippet "Indexed, though blocked by robots.txt". Blocking a page in robots.txt prevents Googlebot from discovering <meta name="robots" content="noindex"> tags. Deindexing requires allowing crawl access while serving on-page noindex tags or HTTP headers.
  2. Blocking CSS, JavaScript, or Font Files: Googlebot renders pages using headless Chromium to assess mobile layouts and visual hierarchy. Blocking styling and script assets causes Googlebot to perceive broken layouts, degrading rankings.
  3. Assuming Root Files Cover Subdomains: Each protocol, subdomain, and port requires its own independent /robots.txt file at host root.
  4. Listing Sensitive Unprotected URLs: The file is completely public; publishing hidden folder names provides attackers with an immediate directory enumeration roadmap.

Evaluating crawler rules across both search engines and AI agents helps maintain organic rankings, detailed in our analysis on Does Blocking AI Crawlers Hurt SEO?

How to Test and Validate Your robots.txt File (And Pair It With llms.txt and agents.txt)

To verify that your /robots.txt file serves a clean 200 OK status, contains zero syntax errors, and pairs with modern AI discovery files, complete 3 validation steps.

  1. Test Server Response Headers via Terminal: Running curl inspects headers and confirms plain-text delivery:
    # Verify HTTP 200 status, Content-Type: text/plain, and raw rules via curl:
    curl -i https://example.com/robots.txt
  2. Audit AI Discovery Protocols: Modern web architectures pair crawler access rules with llms.txt: What It Is and Why Sites Are Adding One produced via the llms.txt Generator, validate autonomous agent permissions with the agents.txt Checker, and benchmark machine readiness using the composite AI Readiness Score Audit.
  3. Inspect Google Search Console Crawling Reports: Navigating to Settings and opening the robots.txt report verifies that Googlebot ingested your latest file version with zero syntax warnings.

Completing these diagnostic checks confirms that search indexers and AI agents receive correct parsing directives without unexpected crawler dropouts.

Establishing a compliant robots.txt file serves as the baseline for modern AI Crawler Access. Implementing the Robots Exclusion Protocol (RFC 9309), mastering User-agent, Disallow, Allow, and Sitemap directives, applying most-specific group and longest-path matching, respecting the Disallow vs noindex SEO rule, and running structured validation ensure reliable crawler coordination across search platforms.

Frequently Asked Questions

Does every website need a robots.txt file? ▾

No, if a website returns 404 Not Found for /robots.txt, search engines simply assume all public pages are allowed to be crawled. However, publishing a clean /robots.txt file is best practice for every production site so you can declare your XML Sitemap URL, block internal search or cart URLs, and manage AI crawler access.

How long does it take for Google to notice changes to my robots.txt file? ▾

Under RFC 9309, Googlebot and other compliant crawlers cache your robots.txt file for up to 24 hours, so changes typically take effect automatically within a day. To force Google to refresh it immediately, open Google Search Console -> Settings -> robots.txt and click Request a recrawl.

Why is Google Search Console warning me "Indexed, though blocked by robots.txt" on pages I tried to hide? ▾

In practice, this is the #1 SEO trap with robots.txt: Disallow blocks crawling, not indexing. A noindex meta tag placed on a page that is also blocked in robots.txt remains unread because Googlebot cannot visit the URL to parse the tag. Removing the Disallow line from robots.txt allows Googlebot to crawl the page, see the noindex tag, and drop it from search results.

Why is my specific bot rule (like User-agent: Googlebot) ignoring the Disallow lines I put under User-agent: *? ▾

In real-world robots.txt audits, people often assume a specific bot inherits the rules from User-agent: * and adds its own rules on top. Under RFC 9309 Section 2.2.1, a specific named User-agent group never merges with the wildcard User-agent: * group (only duplicate groups sharing the exact same User-agent token combine): a bot matches its most specific group and ignores User-agent: * completely. Domain owners copy any shared Disallow lines into the specific bot's group as well.

Last verified: 2026-11-18