Nov
10

What Is a Robots.txt File and How to Create One

11/10/2026 12:00 AM

What Is a Robots.txt File and How to Write One

If you own a website, you may have heard that you need a robots.txt file. It is a very small file, but a mistake in it can hide your whole website from search engines. This guide explains what a robots.txt file is, what it can and cannot do, how to write one, and which mistakes to avoid.

What Is a Robots.txt File?

A robots.txt file is a plain text file that sits in the root folder of your website. It gives instructions to web crawlers, also called bots or spiders, about which parts of your site they may visit. Search engines such as Google and Bing read this file before they crawl your pages.

The file must be at the root of your domain. For example, the file for example.com is found at https://www.example.com/robots.txt. A robots.txt file in a subfolder is not read. Each subdomain and each protocol (http and https) has its own file.

What Robots.txt Can Do

  • Ask crawlers not to visit certain folders, such as an admin area or internal search result pages.
  • Save crawling effort on pages that have no value in search, so crawlers spend more time on your useful pages.
  • Tell crawlers where your XML sitemap is.

What Robots.txt Cannot Do

  • It is not a security tool. The file is public, and anyone can read it. Never use it to hide private files. Protect those with a password.
  • It does not remove a page from search results. If a blocked page is linked from other websites, a search engine may still list the address, usually without a description. To keep a page out of search results, use a noindex tag, and make sure the page is not blocked, or the crawler will never see the tag.
  • It is a request, not a lock. Reputable search engines follow it. Bad bots can ignore it.

The Basic Rules of a Robots.txt File

A robots.txt file is made of short groups of lines. These are the main directives:

  • User-agent: names the crawler that the rules apply to. An asterisk (*) means all crawlers.
  • Disallow: a path that the crawler should not visit.
  • Allow: a path that the crawler may visit, even inside a blocked folder.
  • Sitemap: the full address of your XML sitemap.
  • Crawl-delay: asks a crawler to wait between requests. Some search engines follow it, but Google ignores it.

Paths are case-sensitive, so /Admin/ and /admin/ are different. Google also understands two special characters: the asterisk (*) matches any sequence of characters, and the dollar sign ($) marks the end of an address.

A Simple Example

This file allows all crawlers to visit everything except an admin folder and tells them where the sitemap is:

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

Sitemap: https://www.example.com/sitemap.xml

Many WordPress sites use a file like this. It blocks the admin area but still allows one file that some features need:

User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php

Sitemap: https://www.example.com/sitemap.xml

How to Create a Robots.txt File

  1. Decide what to block. For most small websites the answer is very little: an admin folder and perhaps folders with no public use.
  2. Write the file. You can type it by hand in a text editor, or use our Robots.txt Generator, which builds the text for you from simple options.
  3. Save it as a plain text file named exactly robots.txt, with lowercase letters.
  4. Upload it to the root folder of your website, usually called public_html.
  5. Check it by opening yourdomain.com/robots.txt in your browser. You should see your text.

Common Mistakes to Avoid

  • Blocking the whole site by accident. The line Disallow: / under User-agent: * tells every crawler to stay away from your entire website. This is often left over from a development version of a site.
  • Blocking CSS and JavaScript files. Search engines need these files to see your pages the way visitors see them.
  • Using robots.txt to hide private pages. The file is public, and it can even point people to the places you want to hide.
  • Blocking a page that has a noindex tag. The crawler cannot read the tag if it cannot open the page.
  • Forgetting the sitemap line, or pointing it to the wrong address, for example a version of your domain that redirects somewhere else.
  • Blocking the advertising crawler. If you plan to use Google AdSense, make sure your file does not block its crawler, Mediapartners-Google.

How to Test Your File

  • Open the file in your browser and read it carefully.
  • Use the robots.txt report in Google Search Console to see whether Google can fetch your file and whether it found errors.
  • Use the URL Inspection tool in Search Console on an important page, and check that crawling is allowed.
  • Use our Server Status Checker to confirm that the file returns a normal 200 status.

Frequently Asked Questions

Do I need a robots.txt file?

No. If there is no file, crawlers assume they may visit everything. A file is useful when you want to block certain folders or point to your sitemap.

Where does the file go?

In the root folder of your domain, so that it opens at yourdomain.com/robots.txt.

How long until a change takes effect?

Search engines keep a copy of your file for a while, often up to a day, so changes are not instant.

Does robots.txt improve my rankings?

Not directly. It helps crawlers spend their time on your useful pages, but a good, helpful website matters far more.

Next Steps

Create your file with our Robots.txt Generator, then build and submit a sitemap with our XML Sitemap Generator. To see how a crawler reads one of your pages, try our Search Engine Spider Simulator.