Blog · 7 min read

Robots.txt explained: what to allow, block and avoid

Published

Robots.txt explained: what to allow, block and avoid

A robots.txt file is a small text file that tells search engines which parts of your website they may crawl. Written well, it keeps crawlers away from pages you do not want visited. Written badly, one stray line can hide your entire site from Google.

This guide applies to every website, whether it runs on WordPress, Shopify, Wix, Joomla, Magento or custom code.

What robots.txt does, and what it does not

Where it lives

The file must sit at the root of the domain: https://yourdomain.com/robots.txt. Every subdomain needs its own file. If the file returns a 404, crawlers assume everything may be crawled.

The basic syntax

User-agent: *
Disallow: /cart/
Disallow: /search
Allow: /search/help

Sitemap: https://yourdomain.com/sitemap.xml

What to block, and what to leave alone

Reasonable to block:

Do not block:

The mistakes that cause real damage

  1. Disallow: / for all crawlers. This blocks the whole site. It often arrives when a staging site's file is copied to the live site.
  2. Blocking CSS, JavaScript or images, which stops Google rendering the page properly.
  3. Using it to hide sensitive pages, which advertises their location to everyone.
  4. Typos and wrong case. Paths are case-sensitive, and a misspelt directive is ignored.
  5. A missing or unreachable file. A server error on /robots.txt can make crawlers hold back from the whole site.
  6. A file added or changed by a hacker. If your rules change and you did not change them, run a malware check.

Step 1: create the file

Use the free robots.txt generator to build a file from simple choices, then upload it to the root of your site. Most platforms also have a built-in setting or editor for it.

Step 2: test it

Run your domain through the robots.txt and sitemap tester. It shows whether the file loads, how it reads your rules and whether a given page is blocked. Test your most important pages, such as the home page, product pages and blog posts.

Add a Sitemap: line, and keep the sitemap itself clean. Our guide on creating and submitting an XML sitemap shows how.

Step 4: watch Search Console

In Google Search Console, the Pages report lists addresses "Blocked by robots.txt". Review it after every change to make sure only the pages you meant to block are there.

Common questions

Do I need a robots.txt file?

Not strictly. Without one, crawlers read everything. But a short file with a sitemap line is good practice, and it stops crawlers wasting time on pages with no search value.

Will robots.txt stop my pages appearing in Google?

Not reliably. Use noindex for that, or put the page behind a login.

How long do changes take to apply?

Google usually re-reads the file within a day, but it can take longer for large sites.

Should I block AI crawlers?

That is your choice. Many AI crawlers publish a name you can add under User-agent, and well-behaved ones respect it.

Free tools for this problem

More guides