A robots.txt file is a small text file that tells search engine crawlers which URLs on your site they may visit. That is all it does. It is not a lock, and it is not a way to keep a page out of Google, which is the mistake I see bloggers make most often.
Here is what the file does, what it cannot do, the rules you will actually use and how to check yours, based on Google’s own documentation.
What robots.txt is for
Google describes the file as a way to manage crawler traffic, mainly so your server is not overloaded with requests. It sits at the root of your site, so for a site at example.com it lives at example.com/robots.txt. You can open yours right now by adding /robots.txt to your domain in a browser.
A crawler is a program such as Googlebot that visits pages and reads them. The robots.txt file is the first thing a well behaved crawler checks. Unless you say otherwise in the file, everything on your site is allowed to be crawled.
What robots.txt does not do
This is the part that matters most.
- It does not keep a page out of Google. Google says plainly that robots.txt is not a mechanism for that. If other pages link to a blocked URL, Google can still index the address without visiting the page. It may show up in results with no description.
- It does not force anyone to obey. Googlebot and other respectable crawlers follow it. Others may ignore it, so it is no protection for private files.
- It is not security. The file is public. Anyone can read it, so never list a secret folder in it.
If you want a page out of search results, use a noindex tag or password protection instead. One trap to watch for: if you block a page in robots.txt, Google cannot see a noindex tag on that page, because it never opens it. Do not combine the two on the same page.
The rules you will actually use
A robots.txt file is made of groups. Each group starts with a User-agent line naming who the rules are for, followed by Disallow and Allow lines. Google’s crawlers support these four:
- user-agent names the crawler. An asterisk (
*) means all crawlers except Google’s AdsBot crawlers, which must be named directly. - disallow names a path the crawler should not visit.
- allow names a path that may be crawled inside a folder you have disallowed.
- sitemap gives the full address of your sitemap.
Here is the simple example Google itself uses:
User-agent: Googlebot Disallow: /nogooglebot/ User-agent: * Allow: / Sitemap: https://www.example.com/sitemap.xml
Read it like this: Googlebot may not crawl anything starting with /nogooglebot/, every other crawler may crawl the whole site, and the sitemap lives at the address shown.
A few details that trip people up:
- Paths are case sensitive.
/File.aspand/file.aspare different. - A path must start with a slash. A folder should end with one.
- A
#starts a comment, which crawlers ignore. - The sitemap line needs a full address, including
https://.
The most expensive robots.txt mistake
It is two lines:
User-agent: * Disallow: /
That tells every crawler to stay away from the entire site. It is sometimes switched on while a site is being built and then forgotten at launch. If a new blog is not showing up anywhere in Google, open your robots.txt first and make sure those two lines are not there. If you use WordPress, also check that the setting asking search engines not to index the site is off.
Should you block CSS and JavaScript files?
Google says you can block unimportant resource files if pages will not be significantly affected by losing them. But if blocking them makes the page harder for Google to understand, do not block them. For a blog, the simplest advice is to leave your theme files alone.
How to create or edit your file
- Check whether you already have one. Open
yourdomain.com/robots.txt. Many content management systems, WordPress included, serve a basic file for you. - Use a plain text editor. Not a word processor, which can add curly quotes and hidden characters. Save with UTF-8 encoding.
- Name it exactly robots.txt. You can have only one, and it must sit at the root. A copy inside a subfolder is ignored.
- Upload it to the root of your site. Through your hosting file manager or an SFTP tool. If you are unsure where the root is, your host can tell you.
- Test it. Open the address in a private browser window. If you can read the file there, it is public.
If you use a site builder or a hosted platform, you may not be able to edit the file at all. Google notes that some services give you a search settings page instead. On WordPress, an SEO plugin often has a robots.txt editor.
How to test it in Google Search Console
Search Console has a robots.txt report that shows the files Google found for your site, when they were last fetched and any problems. It only works for a file that is already live. If you have not connected your site yet, start with my guide on how to add your website to Google Search Console. Google finds and starts using your robots.txt automatically, so you do not submit it the way you submit a sitemap.
Robots.txt and your sitemap
Adding a Sitemap: line is a tidy way to tell every search engine where your sitemap is. I explain what a sitemap does and how to submit one in what is a sitemap and how to submit it. The two files do different jobs: the sitemap says what you want found, and robots.txt says where crawlers may go.
A short checklist for a blog
- Open your robots.txt and confirm it does not say
Disallow: /for all crawlers. - Do not block pages you want to rank.
- Do not rely on it to hide private pages.
- Keep the sitemap line pointing to the right address, with
https://. - Re-check the file after a redesign, a plugin change or a move to a new host.
If your AdSense pages ever show crawl errors, the related fix is covered in AdSense ads.txt not found. That is a different file with a different job, but people mix them up.
Common questions
Do I need a robots.txt file?
No. If there is none, crawlers assume everything may be crawled. A file is useful when you want to keep crawlers out of certain areas or point to your sitemap.
Will robots.txt remove a page from Google?
No. Use noindex or password protection. Blocking a page can leave its address in results with no description.
Where do I put the file?
At the root of the site, so it opens at yourdomain.com/robots.txt. It cannot go in a subfolder.
Does robots.txt apply to subdomains?
Each host has its own. Rules at example.com/robots.txt do not cover blog.example.com or the http version of the address.
Can a mistake in robots.txt hurt my traffic?
Yes. Blocking the whole site or your main folders can stop Google from crawling pages you want to rank, which is why a quick check after any change is worth it.
Source: Google Search Central, Introduction to robots.txt and How to write and submit a robots.txt file.
