A robots.txt file tells search engines which pages on your site they can and cannot crawl

A robots.txt file is a plain text document that sits in your website's root directory — the top level, at something like example.com/robots.txt. Search engine crawlers (the automated programs that index your site) check this file first before they start crawling your pages. The file contains rules that say "crawl this section" or "do not crawl that section."

You do not need a robots.txt file for Google or Bing to index your site. If you do not have one, they will crawl everything that is publicly accessible. But if you have pages you want to keep private, or if you want to prevent crawlers from wasting time on duplicate content or resource-heavy sections, a robots.txt file is the standard way to communicate that.

The file uses a simple format: a user-agent (the name of the crawler), followed by rules that apply to it. Most sites have one robots.txt that applies to all crawlers, though you can write different rules for different ones.

Key Takeaways

  • Place your robots.txt file at the root of your domain (example.com/robots.txt), not in a subfolder, or crawlers will not find it.
  • Use the Disallow directive to block crawlers from specific paths, and use Allow to override a broader Disallow rule.
  • The User-agent line specifies which crawler the rule applies to — use an asterisk (*) to apply rules to all crawlers at once.
  • Robots.txt does not hide pages from search results; it only prevents crawlers from visiting them, so use noindex tags or password protection if you need actual privacy.
  • Test your robots.txt file in Google Search Console to confirm crawlers can read it and that your rules work as intended.

The basic structure and syntax

A robots.txt file contains one or more blocks, each starting with a User-agent line. Here is the simplest possible example:

User-agent: *Disallow: /admin/

This says "for all crawlers (the asterisk means all), do not crawl anything in the /admin/ folder." The forward slash matters — /admin/ blocks the admin folder and everything inside it, while /admin blocks only a file or folder literally named "admin" at the root level.

You can list multiple Disallow rules in the same block, and they all apply to the same User-agent:

User-agent: *Disallow: /admin/Disallow: /private/Disallow: /temp/

If you want to allow crawlers to access a specific page inside a blocked folder, use the Allow directive:

User-agent: *Disallow: /admin/Allow: /admin/public-page.html

The order matters here — crawlers read from top to bottom and stop at the first matching rule. So if you have Disallow: /admin/ first, then Allow: /admin/public-page.html second, the Allow rule will override the Disallow for that one page.

Blocking specific crawlers while allowing others

You can write different rules for different crawlers by using their actual user-agent names. Google's crawler is called Googlebot, Bing's is Bingbot, and so on. If you want to block only Bing from a certain folder, you would write:

User-agent: BingbotDisallow: /private/

You can then add a separate block for all other crawlers:

User-agent: *Disallow:

The blank Disallow (with nothing after it) means "do not block anything." So this example blocks Bingbot from /private/ but allows all other crawlers everywhere.

Most sites do not need to block specific crawlers. The main reason to do this is if a particular crawler is consuming too much bandwidth or if you have a business reason to exclude one search engine. For a list of official user-agent names, check the documentation from each search engine.

Controlling crawl rate and sitemaps

You can also tell crawlers how fast to crawl your site using the Crawl-delay directive. This is useful if your server is slow or if you have limited bandwidth:

User-agent: *Crawl-delay: 5

This tells crawlers to wait 5 seconds between requests. Google largely ignores this directive and uses its own crawl budget system instead, but other search engines may respect it. A more reliable way to control crawl rate in Google is through Google Search Console itself.

You can also point crawlers to your XML sitemap file, which lists all the pages you want indexed:

User-agent: *Disallow: /admin/Sitemap: https://example.com/sitemap.xml

The Sitemap line can appear anywhere in the file and applies to all crawlers, regardless of which User-agent block it is in. You can list multiple sitemaps if you have them.

What robots.txt does and does not do

A robots.txt file prevents crawlers from visiting a page, but it does not prevent the page from appearing in search results. If another website links to a blocked page, search engines may still index it based on that link alone, without ever crawling the page itself. If you need to keep a page out of search results entirely, use a noindex meta tag in the page's HTML instead.

Robots.txt also does not provide security. It is a public file that anyone can read — just visit example.com/robots.txt and you can see exactly which folders you are blocking. If you have sensitive information, use password protection or move it to a non-public server instead.

Some crawlers, especially those from less reputable sources, ignore robots.txt entirely. If you need to truly prevent access to a page, use HTTP authentication (a username and password prompt) or restrict access by IP address at the server level.

Common mistakes to avoid

The most common mistake is putting robots.txt in the wrong place. It must be at the root of your domain — example.com/robots.txt, not example.com/pages/robots.txt. If it is in a subfolder, crawlers will not find it.

Another mistake is using wildcards incorrectly. The asterisk (*) in the User-agent line means "all crawlers," but you cannot use wildcards in Disallow paths the way you might in other contexts. To block all files with a certain extension, you have to list the path, not use a pattern like *.pdf. Some crawlers support a limited form of pattern matching, but it is not standard.

People also sometimes block pages they did not mean to block by forgetting the trailing slash. Disallow: /admin blocks a file called "admin" at the root, while Disallow: /admin/ blocks the admin folder. If you want to block both, you need two separate lines.

Finally, do not rely on robots.txt to hide duplicate content from search engines. If you have multiple URLs pointing to the same content, use canonical tags (a rel="canonical" link in the page's HTML) to tell search engines which version is the original.

Testing your robots.txt file

Google Search Console includes a robots.txt tester that shows you exactly what your file says and whether it is blocking pages you intended to block. Log in to Search Console, select your property, go to Settings, and then look for the robots.txt tester. You can enter a URL and see whether your current robots.txt would allow or block it.

You can also check whether your file is readable by visiting it directly in your browser. Go to example.com/robots.txt and you should see the plain text of your file. If you see a 404 error or a blank page, the file is not in the right place or does not exist.

After you make changes to robots.txt, crawlers may not pick them up immediately. Google can take days or weeks to re-crawl your site and notice the change. If you need the change to take effect faster, use the URL inspection tool in Google Search Console to request a recrawl of specific pages.

Frequently Asked Questions

Can I use robots.txt to hide pages from Google search results?

No. Robots.txt prevents crawlers from visiting a page, but if other sites link to it, Google may still index it without crawling it. To keep a page out of search results, add a noindex meta tag to the page's HTML or use a password to restrict access.

What happens if I do not have a robots.txt file?

Search engines will crawl all publicly accessible pages on your site. You only need a robots.txt file if you want to block certain sections or control crawl behavior. Most small websites do not need one.

Can I block a specific page instead of a whole folder?

Yes. Use the full path to the page: Disallow: /admin/secret-page.html. This blocks only that one page, not the entire /admin/ folder. You can list as many individual pages as you need.

Do all search engines respect robots.txt?

Major search engines like Google and Bing do, but smaller or less reputable crawlers may ignore it. Robots.txt is a standard, not a law. For real security, use server-level access controls or password protection.

How often do search engines check my robots.txt file?

Google typically checks it once per day, though the exact frequency varies. Changes can take days or weeks to take effect across all of Google's crawlers. You can request a recrawl in Google Search Console to speed this up.