Cover image: Robots.txt for SEO: A Complete Guide

Short answer

A robots.txt file is a plain text file at the root of your website that tells search engine and AI crawlers which pages and files they may crawl. It manages crawling, not indexing: to keep a page out of Google, use a noindex tag or a password instead.

01Robots.txt controls which parts of your site crawlers may open. It lives at the root, such as example.com/robots.txt.
02It does not keep a page out of Google. A blocked page can still be indexed if other sites link to it.
03Google supports four fields: User-agent, Disallow, Allow and Sitemap. It ignores crawl-delay.
04Each subdomain needs its own file, and Google reads only the first 500 kibibytes.
05AI crawlers such as OAI-SearchBot and GPTBot follow robots.txt too, so decide on purpose whether to allow them.
06Test the file in a private browser window and in the robots.txt report in Search Console after every change.

A robots.txt file is a small text file that tells search engines which parts of your website they may crawl. It sits at the root of your site, for example https://example.com/robots.txt. Every well-behaved crawler reads it before it looks at anything else.

This robots.txt guide explains what the file does, what it cannot do, how to write one, and how to check it. Every rule here comes from Google’s own documentation, which is linked at the end.

Chapter 1 · 1 min

What is a robots.txt file?

A robots.txt file is a plain text file with rules for web crawlers. A crawler is the program a search engine uses to read web pages. Search engine crawlers are also called bots or spiders. Googlebot is Google’s crawler. Bingbot is Bing’s.

Each rule says which crawler it is for and which paths that crawler may or may not open. Rules are also called directives. Google says the file is used mainly to manage crawler traffic, so your server is not overloaded with requests.

The rules follow a standard called the Robots Exclusion Protocol. If a site has no robots.txt file, crawlers assume they may crawl everything.

Chapter 2 · 1 min

How does a robots.txt file work?

Here is what happens when a search engine visits your site:

  1. The crawler first asks for https://yourdomain.com/robots.txt.
  2. If the file loads, the crawler reads it and finds the group of rules that names it. If no group names it, it uses the group for *.
  3. For each address it wants to visit, it checks the rules. If a Disallow rule matches, it skips that address.
  4. It then crawls the addresses that are allowed, and uses your Sitemap line to find more.

The rules are a request, not a lock. Google and other respected web crawlers follow them. Some crawlers do not. That is why robots.txt files are good for managing crawling and poor for keeping things secret.

Chapter 3 · 1 min

Why is robots.txt important for SEO?

Search engines do not have unlimited time for your site. SEO people call that time your crawl budget. Robots.txt helps crawlers spend it on the pages that matter.

  • It keeps crawlers out of pages with no search value. Think of admin screens, cart pages and internal search results. The same goes for pages that are near copies of each other (duplicate content), such as filtered product lists.
  • It protects your server. On a large site, crawlers can make many requests. Rules reduce that load.
  • It can keep media files out of Google. Google says you can use it to stop images, video and audio files from showing in search results.
  • It points crawlers to your sitemap. One line tells them where the list of your important pages is.

A good SEO robots.txt file is short and careful. A mistake here can also do real harm. One wrong line can block your entire site from being crawled. That is why this file deserves care.

Chapter 4 · 1 min

How does robots.txt help with crawl budget?

Google cannot crawl every page on the web. It gives each site a limited amount of crawling time and effort. SEO people call this your crawl budget. Google says it depends on two things: how much crawling your server can handle, and how much Google wants to crawl your content.

Google also says crawl budget matters mainly for two kinds of sites: very large sites (about 1 million pages or more) and medium or large sites (about 10,000 pages or more) whose content changes every day. If you run a small business site, you probably do not need to worry about it.

For sites where it does matter, Google gives clear advice about robots.txt:

  • Block pages you never want crawled. Good examples are endless internal search results and differently sorted copies of the same page. Blocking them stops Google spending time on them.
  • Do not use noindex for this. Google still has to fetch the page to see the tag, so the crawling time is wasted.
  • Do not use robots.txt to move crawl budget around for a short time. Google will not shift the saved effort to other pages unless it is already hitting your site’s limit.
  • Return a 404 or 410 for pages you removed for good. A blocked address stays in the crawl queue much longer than an error page.

Chapter 5 · 1 min

What can robots.txt not do?

This is the part most guides get wrong, so read it twice.

Robots.txt does not keep a page out of Google. It stops crawling. It does not stop indexing. Google says a blocked page can still appear in search results if other pages link to it. The result will show the address with no description.

To keep a page out of search results, Google tells you to use one of these instead:

  • a noindex tag or header on the page
  • a password on the page
  • removing the page

Do not combine a noindex tag with a block in robots.txt. If the crawler cannot open the page, it never sees the noindex tag.

Robots.txt is not security. The file is public. Anyone can read it. Google also notes that some crawlers do not obey it. Private files need a password, not a line in a text file.

Chapter 6 · 1 min

What does a robots.txt file look like?

Here is a simple file with two groups of rules and a sitemap line.

User-agent: Googlebot
Disallow: /nogooglebot/

User-agent: *
Allow: /

Sitemap: https://www.example.com/sitemap.xml

In plain words: Googlebot may not crawl any address that starts with /nogooglebot/. Every other crawler may crawl the whole site. The sitemap is at the address shown.

Google supports four fields in this file. They are often called robots.txt directives. The Disallow directive blocks a path, and the Allow directive opens one. Together with the user agent and sitemap lines, that is the whole language:

FieldWhat it doesExample
User-agentNames the crawler the rules are for. A star means all crawlers.User-agent: *
DisallowA path the crawler must not open.Disallow: /cart/
AllowA path the crawler may open, even inside a blocked folder.Allow: /cart/help/
SitemapThe full address of your sitemap.Sitemap: https://example.com/sitemap.xml

Google does not support the crawl-delay directive, which some other search engine bots read. Lines it does not understand are ignored.

Chapter 7 · 2 min

How do you create a robots.txt file?

Google describes four steps: create the file, add rules, upload it, and test it.

1. Create a file named robots.txt

Use a plain text editor such as Notepad or TextEdit. Do not use a word processor. Word processors can add hidden characters and curly quotes that break the rules.

Save the file as robots.txt in UTF-8 format. The name must be exactly that, in lower case. A site can have only one.

2. Choose the user agent

Every group of rules starts with a User-agent line. It says who the rules are for.

  • One crawler: User-agent: Googlebot
  • Several crawlers: put each name on its own line above the same rules.
  • All crawlers: User-agent: *

A crawler follows only one group: the one that names it most exactly. If there is a group for Googlebot and a group for *, Googlebot follows its own group and ignores the other. The order of the groups in the file does not matter.

3. Add your rules

Under the user agent, add one rule per line. Each path starts with a slash. A folder ends with a slash too.

User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Disallow: /?s=

Three things to remember:

  • Paths are case-sensitive. /File.pdf and /file.pdf are different.
  • A star is a wildcard. It stands for any text in a path.
  • A line that starts with # is a comment. Use comments to say why a rule exists.

4. Upload the file to the root of your site

The file must sit in the root directory, the top level of your site, such as https://www.example.com/robots.txt. Crawlers do not look for it in a folder.

The file only covers the exact site it is on. Rules on https://example.com do not apply to https://shop.example.com. Each subdomain needs its own file.

On some website builders, such as Wix or Blogger, you may not be able to edit the file yourself. Google says to use the platform’s own search settings in that case. On WordPress, SEO plugins such as Yoast SEO let you edit it from the dashboard.

5. Test it and keep it up to date

First, open the file in a private browser window. If you can see your rules, crawlers can too.

Then open the robots.txt report in Google Search Console. Google lists it as the way to find and fix problems in a file that is already live.

Check the file again after every site change, launch or migration. Google usually keeps a copy for up to 24 hours, so a change may take a day to be picked up.

Chapter 8 · 1 min

How does Google choose between rules that clash?

Sooner or later you will write two rules that both match one address. Google has a clear method. It uses the most specific rule, which is the one with the longest path. If two rules conflict, it uses the least restrictive one, which means the one that allows crawling.

These examples come from Google’s own documentation:

AddressYour rulesRule that appliesWhy
/pageAllow: /p and Disallow: /Allow: /pIt is more specific
/folder/pageAllow: /folder and Disallow: /folderAllow: /folderWhen rules clash, Google uses the least restrictive one
/page.htmAllow: /page and Disallow: /*.htmDisallow: /*.htmThe path is longer, so it is more specific
/ (home page)Allow: /$ and Disallow: /Allow: /$The dollar sign matches only the home page

Two symbols help you write exact rules. The star (*) matches any run of characters. The dollar sign ($) marks the end of the address. Use them sparingly and test after every change.

Chapter 9 · 1 min

Robots.txt examples you can copy

These are the rules most sites need. Change the paths to match your own site.

Allow everything

User-agent: *
Disallow:

An empty Disallow line blocks nothing. This has the same effect as having no file at all.

Block one folder

User-agent: *
Disallow: /checkout/

Every address that starts with /checkout/ is off limits to all crawlers.

Block a folder but allow one file in it

User-agent: *
Disallow: /downloads/
Allow: /downloads/price-list.pdf

The more exact rule wins, so the price list can still be crawled.

Block one type of file

User-agent: *
Disallow: /*.xls$

The star stands for any text. The dollar sign marks the end of the address. Together they match every address that ends in .xls.

Block one crawler only

User-agent: GPTBot
Disallow: /

User-agent: *
Allow: /

Here one named crawler is kept out and all others are welcome.

Add your sitemap

Sitemap: https://www.example.com/sitemap.xml

Use the full address. You can list more than one sitemap, each on its own line.

Chapter 10 · 1 min

Robots.txt for WordPress

If your site runs on WordPress, you can usually edit robots.txt from an SEO plugin such as Yoast SEO, without touching files on the server. A common starting point looks like this:

User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Disallow: /?s=

Sitemap: https://www.example.com/sitemap_index.xml

This keeps crawlers out of the admin area and out of internal search results. It still allows the one admin file that some themes and plugins need on the public site. Do not block the folders that hold your styles and scripts. Google warns that blocking files a page needs can stop it from understanding the page properly.

Chapter 11 · 1 min

Robots.txt examples for different kinds of sites

The right rules depend on the site. These are starting points to adapt, not templates to paste.

An online store

Stores often create thousands of addresses from filters and sorting options, such as ?sort=price. These near-copies waste crawl effort.

User-agent: *
Disallow: /cart/
Disallow: /checkout/
Disallow: /*?sort=
Disallow: /*?filter=

Keep your category and product pages open. Block only the parameters that create copies, and check them first so you do not block pages that rank.

A blog or company site

Small sites need very little. Block the admin area and internal search, add the sitemap, and stop there.

A site under development

Do not use robots.txt to hide a test site. A blocked address can still appear in Google if someone links to it. Protect it with a password. Then, when you launch, check that you did not carry the “block everything” rule across to the live site.

Chapter 12 · 1 min

Do you need a robots.txt file?

No. Google says that unless you write rules, every file on your site may be crawled. A site with no robots.txt works, and Google treats it as having no crawl limits. You need the file when you want to keep crawlers away from certain sections, to point to your sitemap, or to set rules for specific bots such as AI crawlers.

Most sites do have one. The HTTP Archive’s Web Almanac 2025 looked at a July 2025 crawl of more than 16 million websites. It found that 85% of requests for robots.txt returned a valid 200 status, up from 84% in 2024, and that about 13% returned a 404, which means no file. The Almanac warns that a 200 only shows that a file exists. It does not show that the rules inside are right.

Chapter 13 · 1 min

What happens if your robots.txt is missing or broken?

It depends on the error. Google’s documentation sets out how Googlebot treats each status code:

What the server returnsWhat Google does
200 (success)Reads and follows the file as served
Redirect (3xx)Follows at least five hops, then treats the file as a 404
Client error (4xx, except 429)Acts as if no robots.txt exists and assumes there are no crawl limits
Server error (5xx)For the first 12 hours, stops crawling the site and keeps trying to fetch the file. For the next 30 days, uses the last good copy while it keeps trying. After 30 days, if the site is available, it behaves as if there is no file. If the site has general availability problems, it stops crawling

This is why a 5xx error on robots.txt is more dangerous than a missing file. A missing file means no limits. A server error can pause crawling of the whole site. Google also caches the file for up to 24 hours and may keep an old copy longer when it cannot refresh it.

Errors are not rare. In the 2024 Web Almanac, Lighthouse audits found that 8.43% of desktop pages and 7.40% of mobile pages failed the check for a valid robots.txt file. Check yours in the robots.txt report in Search Console.

Chapter 14 · 1 min

Is robots.txt a law or a lock?

Neither. It is a voluntary standard, published as RFC 9309. Google says that its crawlers and other respectable crawlers follow the rules, but the file cannot force any crawler to obey, and some crawlers do not follow it. Do not use robots.txt to protect private information. Use a password or other access control for that. Also remember that anyone can read your robots.txt, so do not list paths you want to keep secret.

Chapter 15 · 1 min

Should you block images with robots.txt?

You can. Google’s documentation says that for media files, robots.txt can manage crawl traffic and can keep image, video and audio files out of Google Search results. It will not stop other sites or people from linking to the file. Do not block image, script or style files that Google needs to understand your pages. If the page is harder to render without them, Google may not analyze it well.

Chapter 16 · 1 min

How do you fix robots.txt problems?

When pages are missing from Google or the wrong ones appear, work through this table:

What you seeLikely causeWhat to do
Whole site missing from GoogleA Disallow: / rule for all crawlersRemove the rule, then request a recrawl in Search Console
A blocked page still shows in results, with no descriptionOther sites link to it, so Google knows the addressTo remove it, use noindex or a password, and unblock it so Google can see the tag
Pages look broken in Google’s previewStyles or scripts are blockedAllow the folders those files sit in
A new rule does not seem to workGoogle keeps a copy of the file for up to 24 hoursWait a day, then check again
The rule blocks too much or too littleA path is missing a slash, or letters are the wrong caseCheck the path against the real address and test it
Google cannot read the fileThe server returns an error for robots.txtFix the server so the file returns a normal response

In Search Console, the robots.txt report shows the file Google found and any lines it could not use. A page marked as blocked by robots.txt in the page indexing report should be one you chose to block.

Chapter 17 · 1 min

What are the most common robots.txt mistakes?

  • Blocking the entire site. The directive Disallow: / under User-agent: * stops all crawling. This is often left over from a test site.
  • Using it to hide pages. Blocked pages can still be indexed. Use noindex instead.
  • Blocking files a page needs. Google warns against blocking style and script files if the page is hard to understand without them.
  • Putting the file in a folder. It only works at the root.
  • Forgetting subdomains. Each one needs its own file.
  • Letting the file break. If your server returns an error for robots.txt, Google stops crawling the site for the first 12 hours. It then uses the last good copy for up to 30 days.
  • Making it too big. Google reads only the first 500 kibibytes.

Chapter 18 · 1 min

Robots.txt best practices

  • Keep the file short. Fewer robots.txt rules mean fewer mistakes.
  • Block sections, not single pages. Use one rule for a folder where you can.
  • Add the sitemap directive. It helps crawlers find your important pages.
  • Write a comment above each rule. Say why it is there, so the next person does not have to guess.
  • Check Search Console. A page marked as blocked by robots.txt there should be one you meant to block.
  • Review the file after every launch or migration. Test sites often carry a rule that blocks everything.

Chapter 19 · 1 min

Robots.txt and your sitemap

A robots.txt file tells crawlers where not to go. An XML sitemap tells them what you want found. They work together. Google says sitemaps are a good way to show which content you want crawled, as opposed to which content it can or cannot crawl. Put the full sitemap address in your robots.txt file, and make sure no page in your sitemap is blocked by a Disallow rule. A page that is both listed and blocked sends mixed signals.

Chapter 20 · 1 min

Robots.txt checklist before you publish

Run through this list every time you change the file:

  • The file is named robots.txt and sits at the root of the site.
  • It is plain text in UTF-8, saved from a text editor, not a word processor.
  • No rule blocks pages you want to rank, or the style and script files they need.
  • There is no Disallow: / under User-agent: * unless you mean it.
  • Each path starts with a slash and has the right letter case.
  • Your sitemap address is listed in full.
  • You decided on purpose whether to allow AI search crawlers.
  • You tested the file in a private browser window and in Search Console.
  • Each subdomain has its own file.

Chapter 21 · 1 min

Robots.txt and AI crawlers

AI tools read the web too, and each one has its own crawler name. You can allow or block them in robots.txt like any other crawler.

Crawler nameWho runs itWhat it is for
OAI-SearchBotOpenAIShowing sites in ChatGPT search answers
GPTBotOpenAICollecting content that may be used to train its models
Google-ExtendedGoogleControls use of your content for Gemini training and grounding

Two facts matter here. OpenAI says sites that block OAI-SearchBot will not be shown in ChatGPT search answers. Google says Google-Extended does not affect your place in Google Search.

So decide on purpose. If you want AI answers to name and cite your business, do not block the search crawlers.

Many sites now set AI rules. In the Web Almanac 2025, GPTBot was named in the robots.txt files of 4.5% of desktop sites, up from 2.9% in 2024. ClaudeBot rose from 1.9% to 3.6%, CCBot (Common Crawl) was at 3.5% and Google-Extended at 3.4%. The Almanac counts sites that name a crawler, and a rule can allow it as well as block it, so these are not the share of sites that block it. The Almanac’s authors called the growth one of the fastest expansions of named user agents in robots.txt in recent memory.

Chapter 22 · 1 min

Robots.txt or a meta robots tag: which one?

They do different jobs. Use the one that fits the goal.

Your goalUse this
Stop crawlers wasting time on a sectionRobots.txt
Keep one page out of search resultsA noindex meta tag
Keep an image or video file out of search resultsRobots.txt
Keep a PDF out of search resultsA noindex header
Keep something privateA password

Robots.txt works on whole sections of a site. A meta robots tag works on one page at a time.

End of chapter 22Next: Wrapping up

Chapter 23 · 1 min

Wrapping up

Robots.txt is short, but it controls how every crawler meets your site. Keep it simple. Block only what has no search value. Never use it to hide pages. Test it after every change.

If your pages are not being crawled or indexed and you are not sure why, the robots.txt file is the first place to look. It is also the first thing our technical SEO services check. To see how AI tools find and cite a site, read about AI search optimization.

A robots.txt file is one piece of technical SEO. Read what else helps search engines crawl and index your site.

Back matter

Glossary A to Z

Crawler
A program a search engine or AI tool uses to read web pages. Also called a bot or spider.
Disallow
A rule that tells a crawler not to open a path.
Noindex
A tag or header that tells search engines not to show a page in results.
Sitemap
A file that lists the pages you want search engines to find.
User agent
The name a crawler gives itself, such as Googlebot. Rules in robots.txt are addressed to user agents.
Questions

FAQs

Do I need a robots.txt file?

Not always. Without one, crawlers assume they may crawl the whole site. A small site with no private or duplicate sections can work without it. Most sites still add one to block admin pages and point to the sitemap.

Can robots.txt remove a page from Google?

No. It only stops crawling. Google says a blocked page can still appear in results if other pages link to it. To remove a page, use a noindex tag, a password, or delete the page.

Where should I put my robots.txt file?

At the root of the site it is for, such as https://www.example.com/robots.txt. Crawlers do not look for it in folders. Each subdomain needs its own file.

How long do robots.txt changes take to work?

Google usually keeps a copy of the file for up to 24 hours. So a change can take about a day to be noticed. OpenAI also says its search systems can take about 24 hours to adjust.

What happens if robots.txt returns an error?

If the file is missing (a 404 error), Google treats the site as having no crawl limits. If the server fails (a 5xx error), Google stops crawling the site for the first 12 hours, then uses the last good copy for up to 30 days.

What is the maximum size of a robots.txt file?

Google reads the first 500 kibibytes of the file. Anything after that is ignored. If your file is close to that size, combine rules or move blocked content into one folder.

Should I block AI crawlers in robots.txt?

It depends on your goal. Blocking OAI-SearchBot keeps your site out of ChatGPT search answers. Blocking GPTBot or Google-Extended only limits use of your content for AI training. If you want AI tools to cite you, allow the search crawlers.

Does Google support crawl-delay in robots.txt?

No. Google lists crawl-delay as a field it does not support. Google supports User-agent, Allow, Disallow and Sitemap.

What is the best robots.txt for SEO?

There is no single best file, because the right rules depend on your site. A good robots.txt for SEO is short: it blocks admin areas, internal search and pages that make endless near-copies, leaves everything useful open, and lists your sitemap. Test it after every change.

What does Disallow: / mean in robots.txt?

It tells the crawlers named in that group not to crawl any page on the site. It is useful on a private test site and a serious mistake on a live one. If your live site is missing from Google, check for this line first.

Does robots.txt affect crawl budget?

It can, on very large sites. Google says crawl budget matters mainly for sites with about 1 million pages or more, or about 10,000 pages or more that change daily. On those sites, blocking pages you never want crawled saves effort. Small sites usually do not need to worry about it.

Do I need a robots.txt file?

No. Google says that unless you write rules, all files may be crawled. You need the file to keep crawlers out of certain sections, point to your sitemap or set rules for specific bots. In the Web Almanac 2025, 85% of robots.txt requests returned a valid 200 status.

What happens if my robots.txt returns a server error?

Google's documentation says that for the first 12 hours it stops crawling the site and keeps trying to fetch the file. For the next 30 days it uses the last good copy. After 30 days, if the site is available, it acts as if there is no file. A 4xx error, except 429, is treated as no file.

How many sites block AI crawlers in robots.txt?

The Web Almanac 2025 found GPTBot named in 4.5% of desktop sites' robots.txt files, up from 2.9% in 2024, and ClaudeBot in 3.6%, up from 1.9%. These figures count sites that name the crawler, which can mean a block or an allow.

[ Start here ]

See where your search visibility stands.

The free Search Authority Diagnostic reviews your visibility in Google and AI answers, and shows what to fix first.