Start a project

Article · Technical SEO · robots.txt · Indexing · 12 min read

robots.txt vs X-Robots-Tag: which to use

robots.txt and X-Robots-Tag do different jobs. robots.txt tells a crawler whether it may request a URL at all. A meta robots tag or an X-Robots-Tag header tells a crawler that has already fetched the response whether it may index that content, follow its links, or show a snippet. If you need a page or a PDF kept out of search results, a crawl rule alone will not reliably do it, and a Disallow combined with noindex is a well-known trap.

On this page 10 sections
  1. Two different jobs: crawling and indexing
  2. What robots.txt can and cannot do
  3. Meta robots on HTML pages
  4. X-Robots-Tag for files, PDFs and anything without a head
  5. A simple rule for choosing
  6. How they interact, including the noindex-and-disallow trap
  7. AI crawlers and the same distinction
  8. Worked examples
  9. Key takeaways
  10. Frequently asked questions

I keep these rules tight on leej.uk, and I built testers for them because a single contradictory line is enough to leave a preview URL in an index, or to hide a page you wanted found. The method below is the one I use when I have to choose.

Two different jobs: crawling and indexing

Crawling is the request. Indexing is the decision to store the URL and, usually, its content, so it can appear in search results. Those steps are separate, and they use separate controls.

A third, weaker effect is worth naming so it does not confuse the choice. Search engines can sometimes list a URL they have not crawled, if they have seen it in a link or a sitemap. They will not have useful content to show, but the URL can still appear. robots.txt does not erase a URL from the web’s memory. noindex does not work on a response the crawler is forbidden to request.

The same split appears in other work I do. A privacy manifest declares what an app may access; it is not the same as the entitlement that actually opens the API. Here, robots.txt is the gate on the request, and the robots tags are the policy on the document.

What robots.txt can and cannot do

A typical file looks like this:

User-agent: *
Disallow: /preview/
Disallow: /search
Allow: /

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

What that can do, when the crawler honours the file:

What it cannot do:

Test the file with the real user-agent tokens you care about, not with a guess. The robots.txt Tester on this site is built for that check. Tokens change, so I will not pretend a list here stays complete.

Meta robots on HTML pages

For an HTML page you can ship a tag in the document head:

<meta name="robots" content="noindex, follow">

Common directives, which can be combined:

You can also target a family of crawlers with name="googlebot" or another token, instead of robots. Unrecognised tokens are ignored by crawlers that do not use them, which is usually what you want.

Two practical rules:

  1. The tag must be in the first HTML response, not injected only after JavaScript runs, if you need crawlers that do not render to see it.
  2. The page must be allowed in robots.txt for the crawlers that should honour the tag. Otherwise they may never fetch it.

noindex on a thank-you page, a faceted filter, or a thin tag index is a normal, precise use. Hiding a whole section you are ashamed of is usually a content problem, not a robots problem.

X-Robots-Tag for files, PDFs and anything without a head

X-Robots-Tag is the same vocabulary, sent as an HTTP header. It is the right tool whenever there is no HTML <head> to put a meta tag in, or when you want one rule at the server for a class of responses.

HTTP/1.1 200 OK
Content-Type: application/pdf
X-Robots-Tag: noindex, noarchive

You can also name a bot:

X-Robots-Tag: googlebot: noindex
X-Robots-Tag: otherbot: nofollow

Use it for:

The header must be present on the response the crawler actually receives, after redirects. A noindex on the redirecting URL is not a substitute for a noindex on the destination, or for leaving the destination out of the sitemap. The X-Robots-Tag Rule Builder is a way to draft the header; you still have to attach it at the origin or the edge and then confirm with a real request, for example via the HTTP Header Inspector if you are already checking headers.

If both a meta tag and an X-Robots-Tag are present, crawlers that support both will generally apply the strictest combination. Do not set them to opposite meanings and hope.

A simple rule for choosing

I use this, in order:

  1. If the URL must not be fetched by strangers, do not publish it. Use authentication, network controls, or do not put the document on a public host. robots.txt is not the control.
  2. If a crawler should not spend time on a path, and you do not need it to read a noindex tag there, disallow the path in robots.txt. Good candidates: internal search result URLs, infinite filter combinations, previews already blocked by noindex and removed from the index, or known duplicate parameter patterns.
  3. If the document should be fetchable but not indexed, allow the crawl and send noindex — a meta tag on HTML, X-Robots-Tag on everything else.
  4. If you only want to limit the snippet or the cached copy, allow the crawl and use snippet directives, not Disallow.
  5. If you want the page in search, do not disallow it, do not noindex it, and list the canonical URL in the sitemap if you keep one.

When I add a new section, I decide this before the first deploy, in the same spirit as maintaining an iOS app after launch: the policy ships with the URL, not as a cleanup ticket after a crawler has already found it.

How they interact, including the noindex-and-disallow trap

The trap is this: you want a URL out of the index, so you add <meta name="robots" content="noindex"> and, to be “safe”, you also add Disallow: /that-page to robots.txt. A crawler that honours robots.txt now cannot fetch the page, so it may never see the noindex. If the URL was already indexed, or is discovered from a link, it can stay in the results as a bare URL. You have blocked the only instruction that would have removed it.

The safer sequence for a URL you want deindexed:

  1. Allow the path in robots.txt.
  2. Serve noindex (meta or X-Robots-Tag) on the live response.
  3. Remove the URL from the sitemap.
  4. Wait until the URL is reported as excluded by noindex in Search Console, or until you have given crawlers reasonable time to refetch it.
  5. Only then, if you still want to save crawl budget, add a Disallow. Understand that a later policy change will be slower, because disallowed paths are fetched less often.

Google Search Console also offers a temporary removal tool. That is a short-term hide, not a substitute for noindex, and it does not apply to every search engine.

Other interactions to watch:

AI crawlers and the same distinction

The same split applies to AI crawlers and fetchers, with one extra policy question: some bots crawl to build a training corpus, some fetch a page only when a person asked a question, and some do both. Tokens and behaviour change, so I will not invent a permanent list here.

What does not change:

The robots.txt and llms.txt Generator will help you keep those files consistent. Test the user-agent strings you actually care about, and review the rules when you change policy, rather than pasting a block from a thread and assuming it still matches the crawler names.

Worked examples

A booking confirmation page. People need to load it. You do not want it in search. Allow it in robots.txt. Add <meta name="robots" content="noindex, follow">. Leave it out of the sitemap. Do not disallow it until, and unless, it has dropped out of the index and you have a reason to stop crawlers requesting it.

A PDF price list at /downloads/prices.pdf. There is no HTML head. Send X-Robots-Tag: noindex on the PDF response. Link it from an indexable page if customers need it. Do not rely on Disallow: /downloads/ if you also want a crawler to see the header, and do not put the PDF in the sitemap.

Preview deployments at preview.example.com. This is not a robots-tag problem first. Password the host, or keep it off the public internet. Add Disallow: / in that host’s robots.txt and a site-wide noindex as defence in depth, never as the only lock.

An image that should be visible on an article but not as its own image-search result. You cannot achieve that with a page-level meta tag alone. Send X-Robots-Tag: noindex on the image response, or keep the file behind a path policy you are willing to live with. Check the response headers, not only the article HTML.

A section you plan to launch next week. Do not list it in the sitemap. A noindex until launch is reasonable if the URLs are already public. Removing the noindex is part of the launch checklist, not a later tidy-up.

Key takeaways

If you want a second pair of eyes on a robots setup that is fighting itself, tell me about it.

Frequently asked questions

What is the difference between robots.txt and a noindex tag?

robots.txt asks a crawler not to request a URL. A noindex tag or header, on a response the crawler is allowed to fetch, asks it not to include that document in search results. The first is about access to the body; the second is about what happens after the body is read.

Can robots.txt noindex a page?

Do not rely on it. There is no portable, officially supported noindex directive in robots.txt for Google Search. If you want a URL out of the index, allow it to be crawled and send a noindex meta tag or X-Robots-Tag.

When should I use X-Robots-Tag instead of meta robots?

Use X-Robots-Tag when the response has no HTML head, when you want to apply a rule to a class of files at the server, or when you want the instruction to sit on the HTTP response itself. For ordinary HTML pages, a meta robots tag in the head is enough and easier to see in the source. You can use both, but they should agree.

Does robots.txt stop a PDF or image being indexed?

Not reliably. Disallowing the path may stop a well-behaved crawler from fetching the file, but the URL can still appear if it is linked elsewhere, and the crawler will not see a noindex you might have wanted to send. To keep a file out of the index, allow the request and send X-Robots-Tag: noindex on that file’s response.

Can I use both robots.txt and X-Robots-Tag together?

Yes, and you often should, as long as they do not cancel each other. A common pattern is to allow a path, noindex the documents you do not want in search, and reserve Disallow for URL patterns you do not need crawlers to fetch at all. Avoid disallowing a path that still needs its X-Robots-Tag to be read.

Written by Lee Johnson. Published 10 November 2026.

All articles · Swift A–Z · Apps

Questions, or an app in mind?

Let's bring your ideas to life. Whether you're envisioning a game-changing Apple Watch app or a transformative iOS experience, I'm here to make it happen.

Start a project