Robots.txt Explained: How to Use It Correctly

A robots.txt file is one of the smallest, simplest files on a website, and also one of the easiest to get catastrophically wrong. A single misplaced line can quietly block search engines from an entire site for weeks before anyone notices the traffic drop. This guide explains what robots.txt actually does, what it does not do, and how to use it correctly without accidentally shutting search engines out of your own content.

What Is a Robots.txt File?

A robots.txt file is a simple text file placed at the root of a website, at a URL like yoursite.com/robots.txt, that gives instructions to search engine crawlers and other automated bots about which parts of the site they are allowed to access. It is one of the first things a well behaved crawler checks before crawling a site, and it uses a small set of directives to allow or disallow access to specific pages or sections.

It is worth being clear about something important here: robots.txt is a set of instructions, not a security measure. It relies on crawlers choosing to respect it voluntarily. Reputable search engines like Google and Bing do respect it, but it does not prevent access the way a password or a server level block would, and it does not stop a page from being viewed directly if someone has the URL.

What Does Robots.txt Actually Control?

This is where a lot of confusion starts, so it is worth being precise. Robots.txt controls crawling, meaning whether a bot is permitted to visit and read a given page. It does not directly control indexing, meaning whether a page appears in search results.

This distinction matters more than it might seem. If a page is blocked in robots.txt but other pages link to it, search engines can still become aware the page exists and may index it anyway, sometimes showing it in search results with no description at all, since the crawler was never allowed to actually read the page’s content. This is a common source of confusion when someone expects robots.txt to remove a page from search results and finds that it has not.

If your actual goal is to keep a specific page out of search results entirely, the correct tool is a “noindex” meta tag on the page itself, not a robots.txt block. In fact, blocking a page in robots.txt while also trying to use a “noindex” tag on it creates a contradiction, since the crawler cannot see the “noindex” instruction if it is never allowed to crawl the page in the first place.

What Does a Basic Robots.txt File Look Like?

A robots.txt file is built from a small number of simple directives. A basic example might look like this:

User-agent: * Disallow: /admin/ Disallow: /cart/ Allow: /

Sitemap: https://yoursite.com/sitemap.xml

Breaking this down: “User-agent: *” means the following rules apply to all crawlers. “Disallow” lines specify folders or pages that should not be crawled. “Allow” can be used to specify an exception within a broader disallowed section. The “Sitemap” line points crawlers toward your XML sitemap, which is a helpful addition even though it is technically optional.

What Should You Actually Block With Robots.txt?

Robots.txt is best used for sections of a site that offer no value to search visibility and would otherwise waste crawler attention. Reasonable candidates include:

  • Admin login pages and backend dashboards
  • Shopping cart and checkout pages, which are functional rather than informational
  • Internal search result pages, which tend to generate large numbers of thin, near duplicate URLs
  • Staging or development environments that should never be indexed at all
  • Certain script or resource folders that have no direct SEO value, though this needs care, since blocking resources that a page actually needs to render properly can cause search engines to see a broken or incomplete version of the page

What Are the Most Common Robots.txt Mistakes?

A surprising number of serious SEO problems trace back to a simple robots.txt error, often introduced without anyone realizing it at the time.

Blocking the Entire Site by Accident

The single most damaging mistake is a leftover rule like:

User-agent: * Disallow: /

This tells every crawler to avoid the entire site, and it is a common leftover from a staging or development environment that gets accidentally carried over when a site goes live or gets redesigned. If a site has mysteriously lost most of its search visibility after a migration or relaunch, this is one of the first things worth checking.

Blocking CSS or JavaScript Files Needed to Render the Page

Search engines, particularly Google, render pages much like a browser does in order to fully understand their content and layout. If important CSS or JavaScript files are blocked, the crawler may see a broken, poorly styled, or incomplete version of the page, which can hurt how well it is understood and ranked, even if the actual page content itself is not blocked.

Using Robots.txt to Try to Remove Pages From Search Results

As covered earlier, this does not reliably work, since a blocked page can still get indexed through external links even without being crawled. The correct approach for removing a page from search results is a “noindex” tag, or in urgent cases, a direct removal request through Google Search Console.

Inconsistent or Conflicting Rules

Robots.txt files that have grown over time, especially through several different people editing them, sometimes end up with contradictory or redundant rules that are hard to reason about. It is worth periodically reviewing the file in full, rather than only ever adding new lines to the bottom without checking how they interact with everything already there.

Forgetting to Update It After a Site Migration or Redesign

URL structures often change during a migration, and a robots.txt file written for an old structure may no longer make sense, either blocking things it should not or failing to block things it should, on the new site.

How Do You Check Your Current Robots.txt File?

Checking your file is simple and worth doing periodically, not just when something seems wrong.

  • Visit yoursite.com/robots.txt directly in a browser to read the current file exactly as crawlers see it
  • Use Google Search Console’s robots.txt testing tool to check whether specific URLs are allowed or blocked under your current rules
  • Review it after any major site change, including redesigns, platform migrations, or significant restructuring, since these are the moments a robots.txt error is most likely to get introduced

How Does Robots.txt Interact With Your XML Sitemap?

The two work well together and serve complementary purposes. Robots.txt tells crawlers where they are not allowed to go, while a sitemap tells crawlers where you specifically want them to go. Referencing your sitemap directly inside your robots.txt file, using a line like “Sitemap: https://yoursite.com/sitemap.xml,” is a simple, low effort way to make sure crawlers can find it easily, even if it has not been separately submitted through a tool like Search Console.

It is worth double checking that nothing listed in your sitemap is also blocked in robots.txt, since that combination sends a contradictory signal: one file says “please index this,” while the other says “you are not allowed to look at this.”

Does Robots.txt Affect SEO Rankings Directly?

Not directly, in the sense that there is no ranking bonus for having a robots.txt file, and a well configured one will not itself boost your rankings. What it does is remove obstacles and wasted crawling activity, particularly on larger sites where crawl budget, meaning the limited amount of attention a search engine allocates to crawling a given site, is a real consideration. Blocking low value pages like internal search results or admin sections can help ensure crawlers spend their limited attention on the pages that actually matter, which is an indirect but real benefit.

A Realistic Take on Robots.txt

It is worth being honest that robots.txt is a small, simple file that rarely needs frequent changes once it is set up correctly, and most of the real risk comes from careless edits or leftover rules from a previous version of the site, not from getting the initial setup wrong. The best practice is not constant tinkering, but periodically confirming the file still reflects what you actually want blocked, especially after any significant site change, and treating any accidental full site block as an emergency to fix immediately, since the cost of leaving it in place, even briefly, can be significant.

Do Different Search Engines Read Robots.txt the Same Way?

Mostly, yes, since robots.txt follows a widely adopted standard that major search engines respect. That said, there can be minor differences in how thoroughly certain crawlers support less common directives, or in how quickly a given search engine notices and applies a change to the file. Google tends to recrawl robots.txt fairly frequently, but it is still worth allowing some time after a change before assuming every crawler has picked it up. You can also target rules at a specific crawler by naming it directly, such as “User-agent: Googlebot,” if you need different rules for different bots, though for most sites a single shared rule set under “User-agent: *” is simpler and sufficient.

Frequently Asked Questions About Robots.txt

Can I use robots.txt to block a competitor from seeing my content? No. Robots.txt is a voluntary instruction aimed at automated crawlers, not a barrier against human visitors, and it does not prevent anyone from viewing a page directly if they have the URL.

Does every website need a robots.txt file? Not strictly, and a site without one will simply be crawled without any restrictions, which is fine for very small, simple sites. That said, having a basic robots.txt file, even a minimal one that mainly just points to your sitemap, is considered good practice and costs almost nothing to set up.

What happens if my robots.txt file itself returns an error instead of loading properly? Behavior here can vary, but as a general rule, if a robots.txt file cannot be retrieved at all, crawlers will often proceed cautiously, sometimes treating this the same as having no file, though this is not guaranteed across all crawlers. It is worth confirming your robots.txt file reliably returns a normal, successful response rather than an error.

Can I have more than one robots.txt file for different subdomains? Yes. Robots.txt rules apply per subdomain, so yoursite.com and shop.yoursite.com would each need their own robots.txt file if you want different rules for each.

Conclusion

Robots.txt is a small file that plays an outsized role in technical SEO, not because it directly improves rankings, but because getting it wrong can quietly block an entire site, or important sections of one, from search engines without any obvious warning. Understand what it actually controls, which is crawling rather than indexing, use it deliberately for low value sections rather than as a blunt tool to hide pages from search results, and check it carefully after any major site change. A well maintained robots.txt file is not glamorous work, but it is one of the simplest ways to make sure nothing you are doing elsewhere in SEO is being silently undone by a single misplaced line.