A robots txt file for SEO is a small text file that tells crawlers which URLs on your site they may request. It is easy to write and easy to get wrong. One bad line can block your whole site. This guide explains what the file does, gives a safe default for WordPress, shows the Rank Math steps, and covers noindex vs robots.txt, AI crawlers and testing.

Quick answer: What is robots.txt? A plain text file at your site’s root that tells crawlers which URLs they can access. Use it to manage crawling, not to hide pages. To keep a page out of Google, use noindex and leave the page crawlable. A wrong Disallow rule can block important pages.
Key takeaways
- Google describes robots.txt as a way to manage crawler traffic, “not a mechanism for keeping a web page out of Google.”
- The file must sit at the root of the host, be named robots.txt and be UTF-8 text.
- Disallow stops crawling. Noindex stops indexing. If you block a page in robots.txt, Google never sees its noindex tag.
- For most WordPress sites, a short default file and a sitemap line are enough.
- Google ignores crawl-delay. Test every change in Search Console and a private browser window.
- Blocking AI crawlers is a separate choice, and each company’s crawler works differently.
In this guide
1. What is robots.txt and why does it matter?
Google’s robots.txt introduction says the file “tells search engine crawlers which URLs the crawler can access on your site.” Its main purpose is to avoid overloading your server with requests. It does not keep a page private or out of Google.
That distinction is the heart of the robots txt file for SEO. The file controls crawling, which is fetching a page. Indexing, which is storing a page so it can appear in results, is a separate step with separate controls.
Compliance is also voluntary. Googlebot and other reputable crawlers follow the file, but some crawlers do not. Never use it to protect private data. Use a login or password for that.
For most small sites it is a quiet file. For large ones, or after a migration, it can decide what gets crawled at all. We cover the wider crawl and index checks in our technical SEO audit checklist.
2. Where does the robots.txt file go and what format does it need?
Google’s creation guide sets these rules:
- The file lives at the root of the site, for example
https://www.example.com/robots.txt. A file in a subfolder is not used. - It must be named
robots.txt. - It must be UTF-8 encoded text. Avoid word processors, which can insert curly quotes.
- A site can have only one file.
- Rules apply only to the protocol, host and port where the file is posted. A subdomain, such as
blog.example.com, needs its own file.
Google also enforces a size limit of 500 KiB. Content past that point is ignored. A normal file is a few lines, so this only matters if you generate very long lists.
3. What does a robots.txt file look like? Syntax in plain words
A file is made of groups. Each group starts with a User-agent line that says which crawler it applies to, followed by rules.
User-agent: *
Disallow: /private/
Allow: /private/public-page.html
Sitemap: https://www.example.com/sitemap.xml
What each line means, based on Google’s documentation:
- User-agent is required. An asterisk matches all crawlers except the AdsBot crawlers, which must be named.
- Disallow blocks a path. It must start with
/. A directory path should end with/. - Allow overrides a Disallow for a page or subfolder inside a blocked folder.
- Sitemap is optional and can appear more than once. It must be a full URL.
- The
*wildcard works in every rule except Sitemap. - A
#starts a comment. Rules are case-sensitive. - Lines Google cannot parse are ignored.
An empty Disallow: line allows everything. A single Disallow: / blocks everything. Those two lines look alike and do opposite things, which is why mistakes happen.
4. How does Google decide when rules conflict?
When two rules match a URL, the more specific rule wins. Google’s robots.txt interpretation guide says the winner is the rule whose path matches the most characters. For example, with Allow: /p and Disallow: /, the URL https://example.com/page is allowed.
When rules are equally specific and conflict, Google applies the least restrictive rule. With Allow: /folder and Disallow: /folder, the URL https://example.com/folder/page is allowed.
Other behavior worth knowing:
- Google caches the file for up to 24 hours, so a change is not instant.
- If the file returns a 4xx error (except 429), Google treats it as if no valid robots.txt exists and assumes no crawl limits.
- If it returns a 5xx error, Google stops crawling for the first 12 hours while it retries, then uses the last good copy for up to 30 days.
- The
crawl-delaydirective is not supported by Google. Do not rely on it.

5. Noindex vs robots.txt: which one keeps a page out of Google?
This is the most common mix-up. Google says robots.txt is not a way to keep a page out of search results. A blocked URL can still appear in results, usually without a description, if other pages link to it.
To keep a page out of Google, Google’s block indexing guide recommends one of these:
- A
<meta name="robots" content="noindex">tag in the page’s head. - An
X-Robots-Tag: noindexHTTP response header. This works for non-HTML files such as PDFs. - A password or login.
Here is the trap. Google says the page “must not be blocked by a robots.txt file.” If it is blocked, the crawler never sees the noindex rule and the page can still appear in search results.
| Goal | Use | Do not |
|---|---|---|
| Keep a page out of Google results | noindex (meta tag or header) | Disallow it in robots.txt |
| Stop crawlers wasting requests on a folder | Disallow | Rely on it for privacy |
| Protect private content | Password or login | Use robots.txt |
| Remove a PDF from results | X-Robots-Tag noindex | Block it and expect removal |
| Let Google read a noindex tag | Keep the page crawlable | Disallow the same URL |
If you need pages like thank-you pages or internal search results kept out of results, add noindex and leave them crawlable. If a page is already crawled and listed, our guide on crawled but currently not indexed covers the other direction.
6. What is a safe robots.txt for WordPress?
WordPress creates a virtual robots.txt if no physical file exists. According to the WordPress developer reference, the default output starts with User-agent: *, then a Disallow for the admin path and an Allow for admin-ajax.php.
A safe starting point for most WordPress sites looks like this:
User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Sitemap: https://www.example.com/sitemap_index.xml
Replace the sitemap URL with your real one. Rank Math, Yoast and other plugins publish a sitemap at their own address, so open yours in a browser and copy it.
Why keep it short? Because every extra Disallow is a way to hide something by accident. Google also warns that blocking script and style files can hurt its understanding of pages that depend on them.
Do you need to block /wp-content/ or /wp-includes/? Usually not. Do not block them without a reason, because they hold CSS, JavaScript and images that pages need to render.
7. How do you edit robots.txt in WordPress with Rank Math?
If you use Rank Math, you can edit the file in the dashboard. These steps follow Rank Math’s documentation.
- Delete any physical
robots.txtfile from your site’s root folder using FTP or your host’s file manager. A physical file can conflict with Rank Math’s virtual one. - In WordPress, go to Rank Math SEO and make sure Advanced Mode is on.
- Open General Settings, then Edit robots.txt.
- Edit the rules in the text area. Rank Math adds default rules, including your sitemap.
- Test the changes with the built-in tester (PRO) or the external robots.txt tester linked under the editor (free).
- Click Save Changes.
If you would rather manage a manual file, upload robots.txt to the root folder instead and ask your host if you are unsure where that is.
Our WordPress SEO services include checking this file, and our WordPress SEO setup guide shows where it fits in a full plugin setup.

8. What is the “Discourage search engines” setting in WordPress?
WordPress has a Settings, Reading option called “Discourage search engines from indexing this site.” The WordPress reference notes that since version 5.3.0 this is handled with a robots meta tag, not a Disallow: / line in robots.txt.
That matters in two ways. First, if you launch a site and forget to turn this off, the site can stay out of results. Second, if you see Disallow: / in your robots.txt on a live site, someone or something added it on purpose or by accident. Check both places after every launch.
Rule of thumb: use a full block only on a development or staging site, and prefer a login on staging so nobody can reach it. After you go live, open /robots.txt, view the page source of your home page and check for noindex in the head.
9. What are the robots.txt mistakes that deindex sites?
Mistakes that cost real traffic are usually small:
Disallow: /on a live site. Copied from staging after a launch. It blocks everything for the crawlers it covers.- Blocking CSS and JavaScript. Google says this can hurt its understanding of pages that depend on them.
- Using Disallow to remove a page from Google. It does not remove it, and it hides any noindex tag.
- Putting the file in the wrong place. It must be at the root of the exact host.
- Wrong case or typos. Rules are case-sensitive and lines that do not match a directive are ignored.
- Smart quotes or non-UTF-8 encoding from a word processor.
- Blocking a folder that holds pages you want ranked, such as
/blog/or/products/. - Forgetting that subdomains need their own file.
- Leaving an old physical file that overrides your plugin settings.
If traffic drops after a change, check robots.txt first. Our full technical audit walkthrough and the broader SEO audit checklist both include it.
10. How do you test a robots.txt file?
Test every change. Google’s guide lists these steps:
- Open the file in a private browser window, such as
https://example.com/robots.txt, to confirm it is public. - Open the robots.txt report in Search Console. It shows whether Google fetched the file and flags parsing errors. It is available for domain-level properties.
- Check the status. “Fetched” means Google got the file. “Not found (404)” means no file exists and Google assumes it may crawl everything.
- Use the URL Inspection tool to test whether a specific URL is blocked.
- After fixing a problem or unblocking important URLs, use “Request a recrawl” in the robots.txt report. Google does not guarantee an immediate recrawl.
Because Google caches the file for about 24 hours, give it time before you judge a change.
Developers can also test locally with Google’s open-source robots.txt library.
11. Robots.txt checklist before you publish
- The file sits at
/robots.txton the exact host and loads in a private window. - It is UTF-8 text with one directive per line.
- No
Disallow: /unless the site is meant to be blocked. - CSS, JavaScript and images are not blocked.
- Pages you want out of Google use noindex and are not disallowed.
- The sitemap URL is correct and fully qualified.
- Any physical file has been removed if a plugin manages the file.
- The report in Search Console shows no errors.
- You have a copy of the old file before editing.

12. Should you block AI crawlers in robots.txt?
It is a business choice, not an SEO requirement. Here are the documented facts.
- Google-Extended is a robots.txt token that controls whether your content may be used for training future Gemini models. Google says it “does not impact a site’s inclusion in Google Search nor is it used as a ranking signal.” Google also plans support for an AIPREF training signal in early 2027.
- GPTBot is OpenAI’s crawler for content that may be used to train its models. Disallowing it says your content should not be used for training.
- OAI-SearchBot is for ChatGPT search. OpenAI says sites that opt out “will not be shown in ChatGPT search answers.”
- ChatGPT-User handles user-initiated visits, and OpenAI notes that robots.txt rules may not apply.
So blocking a training crawler and blocking a search crawler have different effects. If you want to appear in AI answers, do not block the search-related crawlers. We cannot verify how every other AI crawler behaves, so check each company’s current documentation before you add rules. For the wider topic, see our guide on how to rank in AI Overviews.
13. Does robots.txt affect crawl budget?
For most small sites, not much. Google’s crawl budget guide is aimed at sites with more than a million pages that change weekly, or more than 10,000 pages that change daily, as a rough estimate. If your site is smaller, you do not need to tune robots.txt for crawl budget.
Where it helps: large shops with filter URLs, internal search pages or endless calendar links. A Disallow on those low-value patterns saves crawler requests. Test carefully so you do not block pages that should rank.
14. Common mistakes when using a robots txt file for SEO
Beyond the technical errors above, these habits cause trouble:
- Treating robots.txt as a security tool.
- Editing it live without a copy of the old version.
- Adding rules from a random blog post without understanding them.
- Never checking it again after a redesign, migration or theme change.
- Blocking pages and then wondering why a noindex tag does nothing.
- Over-blocking because a tool flagged “too many URLs.”
When in doubt, keep the file shorter, not longer.
15. Next steps
- Open
/robots.txton your site now and read every line. - Compare it to the safe default above and remove anything you cannot explain.
- Check Search Console’s robots.txt report for errors.
- Check key pages for noindex tags you did not intend.
- If something changed after a launch, check the “Discourage search engines” setting too.
- Re-check after any migration, redesign or plugin change.
If you want a wider review, our search optimization team can run crawl and index checks.
FAQ
What is robots.txt?
Robots.txt is a plain text file at the root of your site that tells crawlers which URLs they can access. Google says its main purpose is to manage crawler traffic. It is not a way to hide a page from Google or to protect private content.
Where do I put a robots.txt file?
At the root of the host, for example https://www.example.com/robots.txt. It must be named robots.txt and be UTF-8 text. A file in a subfolder is not used, and each subdomain needs its own file. Check it loads in a private browser window.
Does Google always obey robots.txt?
Google says its crawlers respect robots.txt rules, and other reputable crawlers do too, but compliance is voluntary. Some crawlers ignore it. Because of that, never use it to hide private data. Use a password or login for anything sensitive.
What is the difference between noindex and robots.txt Disallow?
Disallow stops crawlers from fetching a URL. Noindex tells Google not to show a page in results. If a page is disallowed, Google cannot see its noindex tag, so the page can still appear in results. Use noindex and leave the page crawlable.
Can robots.txt remove a page from Google?
No. Google says robots.txt is not a mechanism for keeping a page out of Google. A blocked URL can still appear without a description. Use a noindex meta tag or X-Robots-Tag header, a password, or remove the page if it should be gone.
How do I edit robots.txt in WordPress?
With Rank Math, delete any physical robots.txt file, turn on Advanced Mode, go to General Settings, then Edit robots.txt, make your changes and save. You can also upload a manual file to the site root. Test the result in a private window and in Search Console.
Should I block AI crawlers in robots.txt?
That depends on your goals. Google-Extended controls Gemini training and does not affect Google Search. OpenAI says blocking OAI-SearchBot keeps a site out of ChatGPT search answers, while GPTBot relates to training. Check each company’s current documentation before adding rules.
How do I test my robots.txt file?
Open the URL in a private window, then check the robots.txt report in Search Console for fetch status and parsing errors. Use the URL Inspection tool to test whether a specific URL is blocked. Remember Google caches the file for up to 24 hours.
Want us to check your robots.txt?
If you are not sure what your robots txt file for SEO is doing, we are happy to look at it with you. Send us your site through our contact page and we will tell you what we find, with no pressure. Our SEO services also cover wider crawl, index and speed checks, and our WordPress speed optimization work covers the rest of the technical side.