What does robots.txt do?
A robots.txt file tells crawlers which URLs on a site they may and may not request. It is a plain-text file at the root of a host, such as https://www.example.com/robots.txt, and well-behaved crawlers read it before fetching other pages.
- One file per host: each combination of protocol, host and port needs its own file, so
shop.example.comand thehttp://version of a site are treated separately. - A published standard: the Robots Exclusion Protocol was formalized as RFC 9309 in 2022.
- Size limit: Google reads the first 500 KiB of the file and ignores anything after that.
- Caching: Google generally caches robots.txt for up to 24 hours, so edits are not picked up instantly.
- Status codes matter: a 404 is treated as having no restrictions, while server errors can make Google pause crawling the site for a while.
Its main job is managing crawler traffic: keeping bots out of URL spaces that waste their time, such as endless filter combinations, and pointing them to your sitemaps. Google's robots.txt introduction is the authoritative reference for how Googlebot reads the file.
What is the difference between crawling and indexing?
Crawling is a search engine fetching a URL; indexing is storing and analyzing that page so it can appear in results. robots.txt controls crawling only, so a disallowed URL can still be indexed, usually without a description, if other pages link to it.
This decides which tool to use. A blocked page is never fetched, so a crawler never sees a noindex instruction on it. Google stopped supporting noindex inside robots.txt in September 2019, which leaves a robots meta tag or an X-Robots-Tag HTTP header, on a page crawlers are allowed to fetch, as the reliable way to keep it out of results.
| Goal | Use | Not this |
|---|---|---|
| Stop crawlers wasting time on a URL space | robots.txt Disallow | noindex alone, which still needs crawling |
| Keep a page out of search results | noindex meta tag or X-Robots-Tag, with crawling allowed | robots.txt Disallow |
| Consolidate duplicate pages | Canonical tags or redirects | robots.txt Disallow |
| Keep private content private | Authentication | robots.txt of any kind |
| Remove a URL from Google quickly | Search Console Removals tool, then noindex or a 404/410 | Blocking it in robots.txt |
How are robots.txt rules matched?
A crawler first picks the one group whose User-agent line most specifically matches its name, then applies the most specific rule in that group, meaning the one with the longest matching path. If an Allow and a Disallow rule match with equal length, Google uses the less restrictive Allow.
User-agent: *
Disallow: /search
Allow: /search/help
User-agent: Googlebot
Disallow: /drafts/Here Googlebot follows only its own group, so it may crawl /search but not /drafts/. A crawler with its own group ignores the * group entirely; rules are not merged across groups. Every other crawler follows the * group, where /search/help is allowed because that rule is longer than /search.
| Rule | Matches | Does not match |
|---|---|---|
Disallow: /search | /search, /search?q=shoes, /search-tips | /Search |
Disallow: /search/ | /search/results | /search |
Disallow: /*?sort= | /shoes?sort=price | /shoes?color=red&sort=price |
Disallow: /*.pdf$ | /files/guide.pdf | /files/guide.pdf?v=2 |
* matches any sequence of characters and $ marks the end of the URL. User-agent names are not case-sensitive, but paths are.
When is Disallow the right tool?
Use Disallow to stop crawlers spending time on URLs that have no search value and can multiply almost endlessly. It is a crawl-efficiency tool, and it matters most on large or highly dynamic sites.
- Internal search results: pages such as
/search?q=can generate unlimited low-value URLs. - Faceted filters and sort orders: combinations of color, size, price and sort can create huge numbers of near-duplicate URLs.
- Calendars and other infinite spaces: date pickers or “next” links that never run out.
- Cart, checkout and account flows: pages that only make sense for a signed-in visitor.
- Staging and preview environments: as a backup to authentication, never instead of it.
Do not use Disallow to fix duplicate content, remove indexed pages or hide sensitive information; the table above lists better tools for each. Never block CSS, JavaScript or images that pages need to render, because search engines evaluate pages as they appear once rendered. For crawl planning on larger sites, see our technical SEO service.
What does a good robots.txt file look like?
A good robots.txt file is short, blocks only what you have a clear reason to block and lists your sitemaps with full URLs. Most business websites need only a few lines.
# https://www.example.com/robots.txt
User-agent: *
Disallow: /search
Disallow: /cart
Disallow: /account/
Sitemap: https://www.example.com/sitemap.xmlUser-agent: *
Disallow: /search
Disallow: /checkout/
Disallow: /*sort=
Disallow: /*filter=
Sitemap: https://www.example.com/sitemap-index.xmlUser-agent: *
Disallow: /Sitemap: lines are independent of user-agent groups, can appear anywhere in the file and must use absolute URLs. You can list several or point to a sitemap index; our XML sitemap guide explains how to structure them. Google ignores Crawl-delay and Host, so leave them out unless another search engine you rely on uses them. Lines starting with # are comments, which are useful for noting why each rule exists.
Is robots.txt a security control?
No. robots.txt is a public, voluntary convention, not a security mechanism. Anyone can read the file in a browser, and while reputable crawlers choose to follow it, scrapers and malicious bots can simply ignore it.
That has two practical consequences. First, listing a sensitive path such as /private-reports/ in robots.txt advertises exactly where it is. Second, a blocked URL that is linked from anywhere can still be discovered and, as explained above, can even appear in search results as a bare URL.
- Protect private areas with authentication, such as a login or HTTP basic auth on staging.
- Restrict internal tools with an IP allowlist or VPN where possible.
- Use noindex for public pages that simply should not appear in search.
- If confidential data has been exposed, remove it from the server, rotate any affected credentials and then request removal in Search Console.
What are the most common robots.txt mistakes?
The most damaging mistakes are the ones that silently block important content or expect the file to do a job it cannot do. Check for these first:
- `Disallow: /` left over from staging. The site launches with the staging file and blocks every crawler until someone notices traffic falling.
- Blocking CSS and JavaScript. Rules such as
Disallow: /assets/can stop search engines rendering pages properly. - Hiding private data with robots.txt. The file is public and voluntary, as covered above.
- Adding `noindex` to robots.txt. Google has not supported it since September 2019, so it does nothing.
- Blocking a page you want deindexed. The crawler can no longer fetch the page, never sees its noindex tag, and the URL may linger in results.
- Forgetting group precedence. Adding a
Googlebotgroup means Googlebot stops reading the*rules, including ones you still wanted applied. - Wrong location. A file at
/blog/robots.txtor on the wrong subdomain is ignored. - Case slips.
Disallow: /Admindoes not block/admin.
How do you test crawler access?
Test crawler access with Search Console's robots.txt report, which shows the files Google has fetched for your site, and the URL Inspection tool, which tells you whether a specific URL is blocked. Check both after any change to the file.
- 1
Fetch the file yourself
Open
/robots.txton each host in a browser, or runcurl -Iagainst it, and confirm a 200 status with a plain-text content type. - 2
Review the robots.txt report
In Google Search Console, open Settings and then the robots.txt report to see when Google last fetched each file, the fetch status and any parsing problems. You can request a recrawl after an urgent fix.
- 3
Inspect key URLs
Run your most important pages through URL Inspection to confirm crawling is allowed, then use the live test to check the page renders with its CSS and JavaScript.
- 4
Check other crawlers
Bing Webmaster Tools has its own tester, and your server logs show which bots actually request which URLs.
Add a robots.txt check to your release process, because a single deployment can overwrite the file without anyone noticing.
How do you create robots.txt in Next.js?
In the Next.js App Router, add app/robots.ts and default-export a function that returns a MetadataRoute.Robots object; Next.js serves it at /robots.txt. Generating the file in code lets you vary it by environment, so staging rules cannot reach production by accident.
import type { MetadataRoute } from "next";
const BASE_URL = "https://www.example.com";
export default function robots(): MetadataRoute.Robots {
// Block everything only on a deployment explicitly marked as staging.
if (process.env.APP_ENV === "staging") {
return { rules: { userAgent: "*", disallow: "/" } };
}
return {
rules: [
{ userAgent: "*", allow: "/", disallow: ["/search", "/cart", "/account/"] },
// Example policy: opt out of OpenAI model training while
// OAI-SearchBot (ChatGPT search) still follows the * group.
{ userAgent: "GPTBot", disallow: "/" },
],
sitemap: `${BASE_URL}/sitemap.xml`,
};
}rules accepts one object or an array of groups, each with userAgent, allow and disallow, and sitemap accepts a string or an array. Use either app/robots.ts or a static public/robots.txt, not both. Checking for staging rather than for production means a missing variable leaves the live site crawlable; staging should sit behind authentication regardless. The Next.js robots reference lists every option, and our web development team can set this up alongside the sitemap route on new or existing Next.js sites.
Should you allow AI crawlers?
It depends on your goals, because this is a business decision rather than a technical default. Allowing crawlers that power AI search can make your pages eligible to be cited and linked in those products, while blocking training crawlers keeps your content out of future training by providers that honor robots.txt.
| Provider | User agent | Purpose |
|---|---|---|
| OpenAI | GPTBot | Crawling content that may be used to train OpenAI's models |
| OpenAI | OAI-SearchBot | Finding and linking websites in ChatGPT search results |
| OpenAI | ChatGPT-User | Fetching pages when a user asks ChatGPT to visit them |
| Perplexity | PerplexityBot | Indexing websites for Perplexity's search results |
| Google-Extended | A token controlling use of content for Gemini training and grounding; it does not affect Google Search | |
| Anthropic | ClaudeBot | Collecting public web content that may be used to train Anthropic's models |
- Blocking a training crawler applies to future crawling; it does not withdraw content already collected or stop bots that ignore robots.txt.
- Blocking a search crawler such as OAI-SearchBot or PerplexityBot can reduce your visibility in that product.
- Google's AI Overviews and AI Mode are part of Google Search, so Googlebot access and snippet controls, not Google-Extended, govern how your content appears there.
- User-initiated fetchers may be treated differently from automated crawlers, so read each provider's notes.
If being cited in AI answers is a goal, our AEO and GEO services cover the content side of the decision.
robots.txt checklist
Work through this checklist whenever you launch a site, migrate it or edit the file.
Before and after every change
- The file sits at the root of every host and protocol you serve and returns a 200 status.
- No
Disallow: /from staging remains on the live site. - CSS, JavaScript and images needed for rendering are crawlable.
- Disallow rules target only crawl traps such as internal search, filters and checkout.
- Pages you want removed from search are crawlable and carry noindex.
- No private paths are listed; those areas use authentication instead.
- Crawler-specific groups repeat any
*rules they still need. - AI crawler rules reflect a deliberate, documented business decision.
- Every sitemap is listed with an absolute
Sitemap:URL. - The file is under 500 KiB and free of unsupported directives such as noindex.
- The Search Console robots.txt report shows a successful fetch.
- Key URLs pass URL Inspection after each deployment.
Our technical SEO audits include a full review of crawler access, and our SEO standards page lists the baseline rules we apply. Contact us to arrange a review.

