Robots.txt Guide: Syntax, Examples and Common Mistakes
How robots.txt works, the syntax Google follows, copy ready examples, robots.txt vs noindex and the mistakes that block good pages.

A robots.txt file is a plain text file at the root of your domain that tells search engine crawlers which URLs they may and may not request. It uses simple rules: User-agent names the crawler, Disallow blocks a path, Allow opens a path back up and Sitemap points to your XML sitemap. Robots.txt controls crawling, not indexing, so it is the wrong tool for hiding a page from Google.
Almost every technical audit I run includes a robots.txt problem: a staging rule left live, a blocked CSS folder or a Disallow that hides an entire blog. This guide covers the robots.txt syntax Google follows, copy ready robots txt examples, how rules are matched and the mistakes that cost sites traffic.
What Is a Robots.txt File?
Robots.txt is part of the Robots Exclusion Protocol, which became an official internet standard as RFC 9309 in 2022. Well behaved crawlers such as Googlebot and Bingbot fetch it before crawling a site and follow its rules. It is a request, not a lock: bad bots can ignore it, and anyone can read your file at yoursite.com/robots.txt.
Where the file lives
According to Google’s robots.txt specification, the file must sit in the top level directory of the host and applies only to that exact protocol, host and port. That means https://example.com/robots.txt does not cover https://shop.example.com, and a file placed in a subfolder is never checked.
What robots.txt can and cannot do
| Robots.txt can | Robots.txt cannot |
|---|---|
| Stop compliant crawlers fetching URLs | Remove a URL that is already indexed |
| Reduce crawl requests on low value pages | Protect private or sensitive content |
| Point crawlers to your sitemap | Stop bad bots that ignore the rules |
| Set different rules for different crawlers | Pass a noindex instruction to Google |
Robots.txt Syntax Explained
Each group starts with one or more User-agent lines, followed by the rules for those crawlers. Google supports four fields and ignores everything else.
| Field | What it does | Example |
|---|---|---|
| User-agent | Names the crawler the group applies to; * means all crawlers | User-agent: Googlebot |
| Disallow | Blocks paths that start with the value | Disallow: /checkout/ |
| Allow | Permits a path inside a blocked folder | Allow: /wp-admin/admin-ajax.php |
| Sitemap | Gives the full URL of an XML sitemap | Sitemap: https://example.com/sitemap.xml |
Wildcards and pattern matching
Google supports two special characters. The asterisk (*) matches any sequence of characters, and the dollar sign ($) marks the end of the URL. Disallow: /*.pdf$ blocks every URL ending in .pdf, while Disallow: /*?sort= blocks any URL containing that parameter. Paths are case sensitive, so /Blog/ and /blog/ are different rules, while field names and user-agent values are not.
How Google picks the winning rule
When several rules match a URL, Google applies the most specific one, measured by the length of the path. If an Allow and a Disallow rule match with the same length, Google uses the least restrictive rule, which is Allow. A crawler also follows only the most specific user-agent group that names it, so a Googlebot group replaces the * group for Googlebot rather than adding to it.

Limits, caching and errors
Google reads up to 500 KiB of a robots.txt file and ignores anything beyond that. It generally caches the file for up to 24 hours. If the file returns a 4xx error other than 429, Google treats the site as having no restrictions. If it returns a 5xx or 429 error, Google stops crawling for the first 12 hours, then uses the last good cached copy for up to 30 days, so a broken server response on robots.txt can pause crawling across the whole site.
Robots.txt Examples You Can Copy
Allow everything
User-agent: *
Disallow:
Sitemap: https://example.com/sitemap.xml
An empty Disallow means nothing is blocked. This is a fine robots txt example for a small brochure site with no crawl waste.
Block a folder but allow one file inside it
User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
This is the default WordPress pattern. The longer Allow path wins for admin-ajax.php, which some themes and plugins need for front end features.
Block internal search, carts and filters
User-agent: *
Disallow: /?s=
Disallow: /search/
Disallow: /cart/
Disallow: /checkout/
Disallow: /*?orderby=
Disallow: /*?filter_
Online stores and large blogs can generate thousands of near duplicate URLs through search and filter parameters. Blocking them keeps crawl requests focused on pages you want ranked.
Block AI training crawlers
User-agent: GPTBot
Disallow: /
User-agent: Google-Extended
Disallow: /
User-agent: CCBot
Disallow: /
GPTBot is OpenAI’s crawler, CCBot belongs to Common Crawl and Google-Extended is a token that controls whether Google may use your content to train its Gemini models. Blocking Google-Extended does not affect Googlebot or your rankings in Google Search. Think before blocking AI crawlers, because some also feed AI search answers that can send you visitors.
Block an entire staging site
User-agent: *
Disallow: /
Use this only on staging or development hosts, and pair it with password protection. This single line is behind more lost rankings than any other robots.txt disallow I have seen, because it often gets copied to the live site during a launch.
Robots.txt vs Noindex
This is the difference most site owners get wrong. Robots.txt decides whether Google may fetch a URL. A noindex robots meta tag or X-Robots-Tag header decides whether a fetched URL may appear in search results.

Why blocked pages can still show in Google
If a disallowed URL has links pointing to it, Google can index the URL without crawling it, and it often shows with no description. Google stopped supporting noindex rules inside robots.txt in September 2019, so the only reliable way to keep a page out of the index is a noindex tag on a crawlable page. My guide to Google indexing explains how crawling and indexing connect.
When to use each one
- Use robots.txt for crawl waste: faceted filters, internal search, carts, session parameters and admin areas.
- Use noindex for thin pages you still want crawled: tag archives, thank you pages and paginated duplicates.
- Use password protection for anything private. Neither robots.txt nor noindex keeps people out.
Common Robots.txt Mistakes
Blocking CSS and JavaScript files
Google renders pages like a browser. If robots.txt blocks the folders that hold your stylesheets or scripts, Google may see a broken layout and misjudge the mobile version of the page. Keep theme, plugin and asset folders crawlable.
Leaving a staging Disallow live
After every launch or migration, open the live robots.txt and check for Disallow: /. Also check WordPress under Settings, Reading, where the “Discourage search engines” box changes how WordPress handles robots rules.
Using unsupported rules
Crawl-delay, noindex and nofollow lines are ignored by Google. Crawl-delay still works for some other crawlers such as Bing, but if Googlebot is crawling too hard, the fix is at the server level, not in robots.txt.
Blocking pages you want removed
If you add noindex to a page and also disallow it, Google cannot crawl the page to see the noindex, so the URL can stay indexed. Let Google crawl it until it drops out, then decide whether a Disallow rule is still needed.
How to Create and Test Your Robots.txt
Write it by hand or use a generator
A robots.txt file is plain UTF-8 text, so any text editor works. A robots txt generator or robot txt creator can help by building the syntax from checkboxes, but check the output line by line before uploading, since a generator cannot know which folders hold important pages. Upload the file to your site root, or edit it through your SEO plugin if you run WordPress.
Test it in Search Console
The robots.txt report in Google Search Console shows the files Google found for your hosts, the last fetch time and any warnings or errors. After changes, use the URL Inspection tool on a few key URLs to confirm they are not blocked, and recheck the Page indexing report a week later. Robots.txt is check number one in my technical SEO checklist, and the Search Console errors guide explains the “Blocked by robots.txt” status.
Get a second pair of eyes
If your site has thousands of URLs, parameters or several subdomains, a mistake in one line can hide whole sections. My technical SEO service includes a full crawl and robots.txt review, and the free SEO checklist covers the basics you can check yourself.
FAQ
What is a robots.txt file used for?
A robots.txt file tells search engine crawlers which URLs on your site they may request. It is mainly used to stop crawlers wasting requests on low value areas such as internal search results, carts, filters and admin folders.
Does robots.txt disallow remove a page from Google?
No. Disallow only stops crawling. Google can still index a blocked URL if other pages link to it, usually without a description. To remove a page from search, allow crawling and add a noindex meta tag or X-Robots-Tag header.
Where should the robots.txt file be located?
It must sit in the root of the host, for example https://example.com/robots.txt. It applies only to that protocol, host and port, so each subdomain needs its own file, and copies inside subfolders are ignored.
Does Google support crawl-delay in robots.txt?
No. Google ignores crawl-delay and only supports the user-agent, allow, disallow and sitemap fields. Some other crawlers, such as Bing, do read crawl-delay, so it can stay in the file for them.
How do I test my robots.txt file?
Open the robots.txt report in Google Search Console to see the version Google fetched, when it was fetched and any parsing errors. Then use the URL Inspection tool on an important URL to confirm it is not blocked.
Written by Talha Salman. Last reviewed on 5 December 2026. Read how guides are researched and kept up to date on the About page.


