Skip to content
HOSTIGAN
SEO

How to use robots.txt to control what Google crawls

Learn what robots.txt can and can't do, how Allow and Disallow rules are matched, a safe WordPress setup, how to block AI crawlers and how to test your file.

Intermediate 6 min read Updated November 24, 2026

robots.txt is a small text file at the root of your website that tells crawlers which parts of the site they may visit. Used well, it keeps search engines away from internal search pages and admin areas and helps them spend their time on the content that matters. Used carelessly, one line can make an entire website disappear from Google.

This guide explains what robots.txt actually controls, how its rules are matched, what a safe WordPress setup looks like, how to block AI crawlers if you want to, and how to test the file before and after you change it. By the end you will be able to write a robots.txt you fully understand, line by line.

Crawling is not indexing

The most important thing to understand about robots.txt is that it controls crawling, not indexing. A Disallow rule tells Googlebot not to fetch a URL. It doesn't tell Google to forget the URL. If other sites link to a blocked page, Google can still list it in search results, usually with no description.

That leads to a rule people often get backwards: if you want a page out of Google, don't block it in robots.txt. Let Google crawl it and see a noindex instruction instead. Here is which tool to use for which job:

GoalRight tool
Stop crawlers wasting time on low-value URLsrobots.txt Disallow
Keep an HTML page out of search results<meta name="robots" content="noindex">
Keep a PDF, image or other file out of searchX-Robots-Tag: noindex HTTP header
Keep private content privatePassword protection or IP restrictions
Consolidate duplicate pagesCanonical tag or 301 redirect

Warning: robots.txt is public and voluntary. Anyone can read it, and badly behaved bots ignore it. Never use it to hide sensitive paths; listing them there effectively advertises them.

Where the file lives and how it's read

A crawler requests /robots.txt before anything else on a host. The file must be:

  • at the root of the host: https://www.example.com/robots.txt,
  • plain text in UTF-8,
  • reasonably small; Google ignores anything after the first 500 KiB.

Each combination of protocol, hostname and port is treated separately, so shop.example.com needs its own file. On cPanel hosting, the file for your main domain goes in public_html.

How the server answers matters too. A 404 means "no restrictions", so everything may be crawled. A 5xx server error is treated far more cautiously: Google may stop crawling the whole site until the file is reachable again.

The syntax

A robots.txt file consists of groups. Each group starts with one or more User-agent lines followed by Disallow and Allow rules:

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

User-agent: Googlebot-Image
Disallow: /private-images/

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

The key rules:

  • Paths start with / and are case-sensitive: /Search/ and /search/ are different. Directive names like disallow are not case-sensitive.
  • Two wildcards are supported. * matches any sequence of characters and $ anchors the end of the URL. Disallow: /*.pdf$ blocks every URL ending in .pdf; Disallow: /*?sort= blocks URLs with a sort parameter.
  • The most specific rule wins. When both an Allow and a Disallow match a URL, Google follows the one with the longest path. On a tie, Allow wins. That's why Allow: /cart/help/ above overrides Disallow: /cart/.
  • Each crawler follows one group only: the most specific one that names it. If you add a User-agent: Googlebot group, Googlebot ignores the * group completely, so repeat any shared rules there.
  • Sitemap: stands on its own, outside any group, and applies to all crawlers. See How to create an XML sitemap.
  • Unsupported by Google: Crawl-delay is ignored, and Noindex: in robots.txt has never been an official directive and no longer works.

An empty Disallow: means "nothing is blocked". Disallow: / means "everything is blocked".

A sensible robots.txt for WordPress

When there is no physical file, WordPress serves a virtual robots.txt that blocks the admin area and links to its sitemap. SEO plugins can change that output. If you upload a real robots.txt to public_html, it replaces the virtual one entirely.

A solid starting point for most WordPress sites:

User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Disallow: /?s=
Disallow: /search/

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

Change the sitemap line to sitemap_index.xml if you use Yoast SEO or Rank Math.

Don't block /wp-content/ or /wp-includes/. They contain the CSS, JavaScript and images Google needs to render your pages, and blocking them can make Google see a broken, unstyled site. New to WordPress? See How to install WordPress with cPanel.

How to edit the file

  1. Back up the current version. Download it, or copy its contents somewhere safe.
  2. Edit it with your SEO plugin's file editor, or open public_html/robots.txt in cPanel's File Manager; see How to upload files to your website with File Manager.
  3. Keep it short. Every rule should have a reason you can explain. Most sites need fewer than ten lines.
  4. Save, then fetch it in a browser to confirm the live version is what you expect.

Blocking AI crawlers (optional)

Many AI companies crawl the web to train models, and several respect robots.txt. If you don't want your content used that way, you can block their crawlers by name:

User-agent: GPTBot
Disallow: /

User-agent: CCBot
Disallow: /

User-agent: Google-Extended
Disallow: /

A few things to know. Google-Extended is not a separate crawler but a control token: blocking it opts you out of Google's AI training without affecting Google Search. Blocking only works against crawlers that honour robots.txt, it doesn't remove content already collected, and crawler names change, so the list needs occasional updating.

Test your robots.txt

Start from the command line to check that the file is served correctly:

curl -sI https://www.example.com/robots.txt
curl -s https://www.example.com/robots.txt

You want 200 and content-type: text/plain. Then use Google Search Console:

  • Settings → robots.txt shows which robots.txt files Google found, when it last fetched them and any errors or warnings. You can request a recrawl after a change.
  • URL Inspection tells you whether a specific URL is blocked by robots.txt. See How to get your website indexed by Google.

Staging sites and non-HTML files

Don't protect a staging or test site with Disallow: /. It doesn't stop indexing if someone links to it, and the file has a habit of being copied to the live site at launch. Put a password on the staging site instead.

For PDFs and other files that can't carry a meta tag, send an X-Robots-Tag header. On Apache with .htaccess:

<FilesMatch "\.pdf$">
  Header set X-Robots-Tag "noindex"
</FilesMatch>

Don't block those files in robots.txt as well, or Google never fetches them and never sees the header.

Common mistakes

  • Disallow: / left over from development. The classic cause of a site vanishing from Google after launch.
  • "Indexed, though blocked by robots.txt." The page is in Google but can't be crawled. If you want it gone, unblock it and add noindex.
  • Blocked CSS or JavaScript, which stops Google rendering the page properly.
  • Rules that don't match because of the wrong case, a missing leading slash, a Googlebot group that overrides the general one, or the file sitting in the wrong directory.
  • robots.txt returning a 5xx error, which can pause crawling of the whole site.

In short

robots.txt steers crawling, not indexing. Keep it short, block only low-value areas, never block CSS or JavaScript, and remember that the longest matching rule wins and each crawler obeys one group. To keep something out of Google, use noindex or a password. Test every change with curl and Search Console.

Hosting your site at Hostigan

On Hostigan's cPanel web hosting and WordPress hosting, robots.txt lives in your public_html folder, where you can edit it directly in File Manager. Explore our web hosting plans.

Frequently asked questions

Not reliably. A blocked page can still be indexed from links elsewhere. To remove it, let Google crawl the page and add a noindex tag, or protect it with a password.