The robots.txt file helps us control how search engine crawlers access a website.
Although it is a very simple file, it plays an important role in SEO because it allows us to block the crawling of certain sections of a site and guide bots towards the areas that really matter. That said, it is important to remember that robots.txt controls crawling, not indexing. If the goal is to prevent a page from appearing in Google, a noindex directive or another indexing control is needed instead.
Contents
What is robots.txt?
The robots.txt file is a text file located in the root directory of a website.
Its purpose is to tell search engine crawlers which parts of the site they are allowed to access and which parts they should avoid. When a bot arrives on a domain, one of the first things it does is request this file to check whether there are any crawl restrictions in place.
A robots.txt file usually looks something like this:
User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Sitemap: https://www.example.com/sitemap.xmlIn this example, all crawlers are blocked from accessing the /wp-admin/ directory, except for the admin-ajax.php file, which is explicitly allowed.
User-agents
User-agents are how crawlers identify themselves when accessing a website.
By using the User-agent directive in the robots.txt file, we can define rules for specific bots. For example, we could create instructions only for Googlebot or apply the same rules to all crawlers with User-agent: *.
This makes it possible to set more specific crawl rules depending on the bot we want to manage.
Allow and disallow
The main way to tell crawlers whether they can access a section of the site is through the Allow and Disallow directives.
The Disallow directive is used to indicate that a given path should not be crawled. For example:
User-agent: *
Disallow: /checkout/With this rule, crawlers are asked not to access the /checkout/ section of the site.
The Allow directive works in the opposite way. It is mainly useful when a broader section is blocked but a specific URL inside it still needs to remain crawlable. This is a common pattern on websites that need to combine general restrictions with a few exceptions.
The sitemap directive
Another useful directive that can be included in the robots.txt file is Sitemap.
This directive indicates the location of the XML sitemap and makes it easier for crawlers to discover the main URLs of the site.
For example:
Sitemap: https://www.example.com/sitemap.xmlAlthough the sitemap can also be submitted through Google Search Console, adding it to robots.txt is still a simple and valid way to make it easier for search engines to find it.
Why robots.txt matters for SEO
The robots.txt file matters because it helps optimize crawl activity.
Search engines do not crawl websites in an unlimited way. They spend a certain amount of time and resources on each site, so it often makes sense to keep them away from URLs that do not need to be crawled, especially on large websites.
For example, sections such as internal search results, filtered URLs, cart pages, login areas, or other low-value pages may not need to be crawled at all. Blocking these areas can help search engines focus on the pages that are actually important for SEO. This is particularly relevant on large sites, where crawl efficiency matters more.
Still, blocking a URL in robots.txt does not guarantee that it will not be indexed. If Google finds links pointing to that URL, it may still index it without crawling the page itself. That is why robots.txt should not be used as a method to keep pages out of search results.
Things to keep in mind when using robots.txt
The robots.txt file is useful, but it needs to be handled carefully.
A small mistake can end up blocking important parts of the website. For example, an incorrect Disallow: / rule could prevent crawlers from accessing the entire site.
It is also important not to use robots.txt as a way to hide sensitive content. Since the file is public, anyone can access it and see which sections are being blocked. If a page really needs to be protected, it should be secured properly, for example through authentication or another access control method.
In short, the robots.txt file is a simple but important SEO element. Used correctly, it can help search engines crawl a website more efficiently and avoid wasting crawl activity on low-value sections. Used incorrectly, it can create serious visibility problems.

