I once audited a store with 40,000 pages and a crawl budget that vanished every month on filtered URLs nobody would ever buy from. The product pages sat unvisited for weeks, and the fix took four lines in one small text file.
That file was robots.txt, and most site owners never open it, though some have never heard of it. Yet it decides which pages Googlebot visits and which it skips, and a single wrong line can hide a whole site from search. This guide explains what the file does, how to write one, and the seven fixes I apply when a client’s robots.txt is costing them traffic.
A robots.txt file is a text file that lives in the root folder of a website and tells search engine crawlers which parts of the site they may visit. It controls crawling, not indexing. A blocked page can still appear in search results, so treat the file as a traffic controller for crawlers, not as a way to hide pages.
What is robots.txt?
It is a plain text file that sits at the root of a domain, so any site has one at an address like yoursite.com/robots.txt. When a search engine crawler arrives, it asks for this file first and reads the rules inside before it visits anything else. Each rule names a crawler, then says which paths that crawler may open and which it must skip.
The file is a request, not a wall, and Googlebot, Bingbot, and other well behaved crawlers obey it. Bad bots ignore it, so it will never stop a scraper or a hacker. Its real job is to guide the good crawlers toward the pages that matter and away from the pages that waste their time.
People type the name wrong more often than you would think. Moz records about 900 searches a month for “robot.txt” without the s, but the file only works with the s, and servers treat the name as case sensitive. Get the case wrong and crawlers will not find it. The name is robots.txt, all lower case.
Use the file to keep crawlers out of admin pages, internal search results, filtered URLs, and staging copies of a site, not to hide a page from search results or to keep content private. A blocked page can still show up in Google if other pages link to it, because Google never crawls it to learn that it should stay out. For pages you want out of the index, use a noindex tag and let Google crawl the page once to see it.
How robots.txt works
The process is short: a crawler requests yoursite.com/robots.txt, reads the rules that match its own name, then crawls the allowed URLs and skips the rest. If the file does not exist, crawlers assume everything is allowed and crawl the whole site.
If your server returns an error when Google asks for the file, Google plays safe and pauses crawling until it can fetch the file again. That is why a broken server can look like a file problem. A missing file is harmless, but a file the server cannot deliver is not.
Each subdomain needs its own file, because rules on example.com do not cover blog.example.com, and rules on the www version do not cover the version without www. One domain, one file, in the root folder, and remember the file is public. Anyone can open yoursite.com/robots.txt in a browser, so never put private paths, login URLs, or secrets in it.
Robots.txt syntax: the 5 directives that do the work
The whole file runs on five directives: three do the daily work, one points crawlers at your sitemap, and one is a leftover that Google ignores.
| Directive | What it does |
|---|---|
| User-agent | Names the crawler the rules below apply to. A star means all crawlers. |
| Disallow | Tells that crawler not to visit a path. A blank value means nothing is blocked. |
| Allow | Makes an exception inside a blocked folder, so one file or page stays crawlable. |
| Sitemap | Gives the full URL of the XML sitemap so crawlers can find it. |
| Crawl-delay | Asks a crawler to wait between requests. Googlebot ignores it, so do not rely on it. |
Two wildcards make the rules flexible: a star matches any sequence of characters, so Disallow: /*? blocks every URL with a question mark in it. A dollar sign marks the end of a URL, so Disallow: /*.pdf$ blocks PDF files and nothing else. A hash starts a comment, so you can leave notes for the next person who edits the file.
When two rules match the same URL, Google follows the most specific one. A rule for one file beats a rule for the whole folder that holds it, and that is how an Allow line can rescue a single page from a broad Disallow. Google’s own guide to the file explains the matching order in full, and it is the reference I check when a rule behaves in a way I did not expect.
A complete robots.txt example you can copy
Here is a file that fits most small business sites. It blocks the admin area and internal search, keeps one script crawlable, and points crawlers at the sitemap.
# robots.txt for a typical business site User-agent: * Disallow: /wp-admin/ Disallow: /search/ Disallow: /*?s= Disallow: /*?filter= Allow: /wp-admin/admin-ajax.php Sitemap: https://ahmarmustafa.com/sitemap_index.xml
Each line earns its place: the wp-admin block keeps crawlers out of the dashboard. The search block stops them crawling endless internal search pages, and the two parameter rules stop filtered URLs from eating crawl budget. The Allow line keeps admin-ajax.php crawlable, because WordPress needs it for some page features, and the last line hands crawlers the sitemap.

Change the paths to match your own site before you use this file. A rule copied from another site can block pages you need. Read every line, test it, and only then save it.
Robots.txt WordPress: how to edit the file on your site
WordPress creates a virtual version of the file when no physical one exists, and you can edit that virtual file from your SEO plugin. In Rank Math, go to Rank Math SEO, then General Settings, then Edit robots.txt; in Yoast, go to Yoast SEO, then Tools, then File Editor. Paste your rules, save, and open yoursite.com/robots.txt in a browser to confirm the change went live.
A physical file beats a virtual one. Upload a file with that exact name to the root folder of your hosting account with the file manager or FTP, and WordPress will serve it instead of the virtual version. A plugin update can reset the virtual file, and a physical file does not have that risk. Either way, check the live URL after every edit, because the editor saying “saved” is not proof that crawlers see the new rules.
Robots.txt sitemap: point crawlers at your sitemap
The Sitemap directive tells crawlers where your XML sitemap lives. Add one line for each sitemap you have, with the full URL, and Google and Bing both read it. It costs one line and it helps a new crawler find your pages without guessing.
Do not treat it as a replacement for submitting the sitemap in Search Console: the directive is a hint. The submission in Search Console is the direct instruction, and it also gives you the crawl reports that show whether Google actually fetched the sitemap. Keep the sitemap itself clean, with live indexable pages only, so the hint points at pages worth crawling.
Robots.txt tester: check your file before it costs you traffic
Test the file in three places before you trust it: first, open yoursite.com/robots.txt in a browser. If it loads and shows your rules, the file exists and the server delivers it. Second, open the file’s report in Google Search Console, under Settings, which shows whether Google could fetch the file, when it last tried, and which rules it sees. Third, run the file through a free online tester, such as the TechnicalSEO.com validator, and test a few of your important URLs against your own rules.
Look for three things: a Disallow line that matches a page you need ranked. A typo in a crawler name, which makes the whole rule group apply to nobody, and a Disallow: / on its own, which blocks the entire site. I have seen all three on live client sites, and each one had been sitting there for months before anyone checked.
7 costly robots.txt mistakes and the fix for each
Most damage from this file comes from a small set of errors. Here are the seven I find most often, with the fix for each one.
Fix 1: Stop blocking CSS and JavaScript
Google needs your CSS and JavaScript files to render a page the way a visitor sees it. A rule that blocks the folders holding them can make Google judge a page on its raw HTML alone, and that can hurt rankings. Keep those folders crawlable, and if an old rule blocks /wp-content/ or /wp-includes/, narrow it to the exact files you mean to block, or remove it.
Fix 2: Remove the staging block before launch
Developers block a staging site with Disallow: / so Google stays away while the site is built, then the file gets copied to the live site, and the block goes live with it. I check for this on every launch, so open yoursite.com/robots.txt on launch day and read it line by line. A site that launched with a staging block can sit invisible for weeks before anyone notices the traffic never arrived.
Fix 3: Do not use the file to hide a page from search
This is the most common misunderstanding in technical SEO: Disallow stops crawling, and a page Google cannot crawl can still appear in search results, often with no description, because other pages link to it. If a page must leave the index, put a noindex tag on it and let Google crawl it once to see the tag. Use the file for pages that should never be crawled at all, like internal search results and endless filter combinations. I cover the wider picture in my crawl budget guide, where robots.txt is one of the tools that keeps Google’s crawl on the pages that earn traffic.
Fix 4: Watch the case
Servers treat paths as case sensitive, so a rule that blocks /About/ does nothing for a page at /about/, and a file with the wrong case is not the file crawlers ask for. Write every path exactly as it appears in the URL, all lower case where your URLs are lower case, and keep the file name robots.txt. One capital letter is enough to make a rule useless.
Fix 5: Do not block your own sitemap or important folders
A broad rule can catch pages it was never meant to touch: Disallow: /*? blocks every URL with a parameter, which can include product pages that need query strings. Disallow: /products/ blocks the whole catalog, so after every edit, test your money pages against the rules in a tester. If a rule matches a page that earns traffic, rewrite the rule to be narrower.
Fix 6: Give each subdomain its own file
A shop on shop.example.com and a blog on blog.example.com each need their own file in their own root folder, because rules written for the main domain do not travel across. I see this most often after a subdomain launches and inherits nothing, so crawlers treat it as fully open, or after a team assumes the main file covers it. Check each subdomain separately.
Fix 7: Review the file after every redesign and migration
Old rules outlive the pages they were written for: a Disallow for a retired section can block the new pages that replaced it. A rule for a plugin you removed can block a folder that now holds content. Put the file on the checklist for every redesign, migration, and plugin change, and review it once a quarter. It takes five minutes. I run this check as one of the 14 checks in my technical SEO audit, and it has caught a blocking rule on more than one site that was otherwise healthy.
Robots.txt and AI crawlers: should you block GPTBot?
AI companies crawl the web to train their models, and their crawlers obey the file like any other crawler. The names to know are GPTBot for OpenAI, ClaudeBot for Anthropic, CCBot for Common Crawl, and Google-Extended for Google’s AI training. Blocking them stops your content being used for training, and it does not affect your normal search rankings, because Google-Extended is separate from Googlebot, and Googlebot keeps crawling your site either way.
# Block AI training crawlers, keep search crawlers User-agent: GPTBot Disallow: / User-agent: ClaudeBot Disallow: / User-agent: CCBot Disallow: /
Whether to block them is a business choice, not a technical one. Some owners want their content out of training data, while others want the exposure that AI answers can bring. Make the choice on purpose and write it down, so the next person who edits the file knows why those lines are there.
You may also hear about llms.txt, a newer proposal for a markdown file that describes a site for language models. It is a proposal, not a standard, and no crawler has to follow it, so it does not replace the file. Until it becomes a real standard with real adoption, robots.txt is the one that counts.
Robots.txt for ecommerce and large sites
Large sites feel mistakes in this file first, because they have the most URLs a crawler can waste time on. Faceted navigation is the usual problem: a category with ten filters can generate thousands of near duplicate URLs, and Google will crawl them if nothing stops it. Block the parameter patterns, such as /*?color= and /*?size=, and keep the canonical category pages open so the pages that can rank stay crawlable.
Block the pages that never earn traffic, internal search results, cart, checkout, and account pages, and keep product and category pages open. Then watch the Crawl Stats report in Google Search Console once a month. If Google still spends most of its crawl on URLs that never rank, your rules are too loose, and the report will show you exactly where the crawl is going. Fold that monthly check into your SEO reporting, so crawl waste shows up next to rankings and traffic.
Frequently Asked Questions about robots.txt
What is robots.txt?
Robots.txt is a plain text file in the root folder of a website that tells search engine crawlers which parts of the site they may visit. It controls crawling, not indexing, and it is a request that well behaved crawlers obey. It cannot keep a page out of search results on its own.
Does robots.txt affect SEO?
Yes, through crawling. It decides which pages Googlebot spends time on and which it skips, so it shapes how your crawl budget is used. A wrong rule can hide important pages from Google, while a good file steers crawlers toward the pages that earn traffic. It does not directly change rankings, and it cannot remove a page from the index.
How do I create a robots.txt file?
Open a plain text editor and save a file named robots.txt, all lower case. Write your rules, one directive per line, starting with a User-agent line. Then upload the file to the root folder of your domain, so it loads at yoursite.com/robots.txt. On WordPress you can also edit it in Rank Math or Yoast instead of uploading a file.
How do I check my robots.txt file?
Open yoursite.com/robots.txt in a browser to confirm it loads and shows your rules. Then check the file’s report in Google Search Console, under Settings, to see whether Google fetched it and which rules it sees. You can also run the file through a free online tester and check a few important URLs against your rules.
Where is the robots.txt file located?
The file lives in the root folder of the domain, so it loads at yoursite.com/robots.txt. Each subdomain needs its own file in its own root folder. On WordPress, if no physical file exists, WordPress generates a virtual one, which you can edit in your SEO plugin.
What is robots.txt in SEO?
In SEO, the file is a technical tool that manages how search engine crawlers move through a site. It keeps them out of admin pages, search results, and filtered URLs, and it protects crawl budget for the pages that can rank. It sits beside the XML sitemap and internal links as one of the basic controls over crawling.
How do I block a page using robots.txt?
Add a Disallow line with the page path under a User-agent rule, such as Disallow: /private-page/ under User-agent: *. That stops crawlers visiting the page. It does not remove the page from search results. To remove a page from the index, use a noindex tag and let Google crawl the page once to see it.
The bottom line
It is a small file with outsized power, so check yours this week. Open it, read every line, and test it against your important pages. If a rule is there and you cannot explain why, it probably should not be there. I check this file on every technical SEO audit I run, and if you want yours reviewed, see my services and get in touch.