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

A robots.txt file is a small text file that tells search engine crawlers which parts of your website they are allowed to visit. It sits at the root of your domain and is one of the first things a search engine looks for when it arrives. Getting it right helps the right pages get crawled, while a mistake can accidentally hide your entire site from search.
This guide explains what a robots.txt file does, when you need one, and how to create a correct file in just a few minutes.
What a Robots.txt File Actually Does
When a crawler like Googlebot visits your site, it checks for a file at yourdomain.com/robots.txt before doing anything else. That file contains simple rules telling the crawler which folders or pages to skip and where to find your sitemap.
It is important to understand what the file does not do. A robots.txt file requests that crawlers avoid certain areas, but it is not a security feature and it does not guarantee a page stays out of search results. It controls crawling, not privacy.
The Basic Structure of Robots.txt
A robots.txt file is built from a few simple directives:
- User-agent names the crawler the rules apply to, with an asterisk meaning all crawlers.
- Disallow tells the crawler not to visit a path.
- Allow makes an exception inside a disallowed area.
- Sitemap points crawlers to your sitemap so they can find every page.
A simple file that allows everything and points to a sitemap looks like a single user-agent line, an empty disallow line, and a sitemap line. You rarely need anything more complex than that for a small site.
When You Need a Robots.txt File
Every site benefits from having one, even if it only points to the sitemap. You will specifically want custom rules when you need to:
- Keep crawlers out of admin, cart, or staging areas
- Stop search engines from wasting time on low-value pages
- Point all crawlers to your sitemap for faster discovery
- Set a crawl delay if your server is under heavy load
If you do not have a robots.txt file at all, most search engines will simply crawl everything they can find, which is fine for many small sites but not ideal once you have pages you would rather keep out of the index.
How to Create a Robots.txt File
You can write a robots.txt file by hand in any text editor, but it is easy to make a small syntax error that blocks more than you intended. The safest approach is to use a robots.txt generator, which builds a correctly formatted file from simple choices.
The steps are straightforward:
- Choose whether to allow all crawlers, block all crawlers, or set custom rules.
- Add any paths you want to disallow, such as an admin folder.
- Add your sitemap URL so search engines can find all your pages.
- Copy or download the file and upload it to the root of your domain.
Once the file is live at yourdomain.com/robots.txt, you can confirm it works in Google Search Console, which has a tool to test whether specific URLs are blocked or allowed.
Common Robots.txt Mistakes to Avoid
A few small errors cause the most trouble:
- Blocking the whole site by accident. A single disallow slash blocks every page, which is the most damaging mistake.
- Relying on it for privacy. Sensitive pages can still be found and indexed if linked elsewhere. Use a noindex tag or password protection instead.
- Forgetting the sitemap line. Without it, search engines discover your pages more slowly.
- Placing the file in the wrong location. It must be at the root, not in a subfolder.
Frequently Asked Questions
Where do I put the robots.txt file?
Upload it to the root of your domain so it is reachable at yourdomain.com/robots.txt. Crawlers only check that exact location.
Does blocking a page in robots.txt remove it from Google?
Not necessarily. Blocking stops crawling, but a page can still appear in results if other sites link to it. To fully remove a page, use a noindex tag or a removal request.
Do I need a robots.txt file for a small website?
It is recommended even for small sites, if only to point crawlers to your sitemap. It takes a minute to create and helps search engines work efficiently.
Can I edit the file later?
Yes. You can update your robots.txt file any time by editing and re-uploading it. Changes take effect the next time crawlers visit.
Create Your Robots.txt File Now
A correct robots.txt file is one of the simplest technical SEO wins available. Open the robots.txt generator, choose your rules, add your sitemap, and have a working file ready to upload in under a minute. For the bigger picture, see our guide to free SEO tools every small business needs.