Sub topic 10
Meta robots tags and X-Robots-Tag headers
This chapter assumes you know how robots.txt works, that you can read HTTP response headers, and that you understand the difference between an advisory convention and an enforced control. It covers the two per-page ways to give directives to crawlers: the meta robots tag in HTML and the X-Robots-Tag HTTP header.
Why per-page directives exist
robots.txt works at the level of URL paths. It tells a crawler whether it may fetch a URL. It says nothing about what the crawler may do with a page it has already fetched.
Meta robots tags and X-Robots-Tag headers fill that gap. They travel with the response, so they apply to one specific document. A crawler reads them after it has fetched the page, and they describe what it should do with the content: index it, show a snippet, cache it, or follow its links.
| Mechanism | Where it lives | Scope | When the crawler reads it |
|---|---|---|---|
| robots.txt | `/robots.txt` at the host root | URL path patterns | Before fetching a page |
| Meta robots tag | In the HTML `<head>` | One HTML document | After fetching the page |
| `X-Robots-Tag` header | HTTP response header | One response of any type | After the response headers arrive |
The meta robots tag
The meta robots tag is an HTML element placed in the <head> of a page. It uses the name robots, or the name of a specific crawler, and a comma-separated list of directives.
<head>
<meta name="robots" content="noindex, nofollow">
<meta name="googlebot" content="noarchive">
</head>The first tag addresses all compliant crawlers. The second addresses only the crawler that identifies itself with the googlebot name. If both apply to a crawler, search engines generally combine them and apply the most restrictive result. Check each vendor's documentation, because the combination rules are not part of a single shared standard.
Common directives
The following directives are documented by Google and, in most cases, by other search engines. Support differs between vendors.
| Directive | Meaning |
|---|---|
| `noindex` | Do not include this page in search results. |
| `nofollow` | Do not follow the links on this page. |
| `none` | Equivalent to `noindex, nofollow`. |
| `noarchive` | Do not offer a cached copy of the page. |
| `nosnippet` | Do not show a text snippet or video preview. |
| `max-snippet:N` | Limit the text snippet to N characters. |
| `noimageindex` | Do not index images on this page. |
| `unavailable_after: date` | Stop showing the page after the given date. |
The X-Robots-Tag header
The X-Robots-Tag header carries the same directives in the HTTP response instead of in the HTML. This matters for two reasons.
- Files that are not HTML, such as PDFs, images, and plain text files, have no
<head>. A header is the only way to attach a per-document directive to them. - You can set a header for many URLs at once in the web server configuration, without editing each page.
HTTP/1.1 200 OK
Content-Type: application/pdf
X-Robots-Tag: noindex, noarchiveYou can also address a single crawler by putting its name before the directives:
X-Robots-Tag: googlebot: nosnippet
X-Robots-Tag: otherbot: noindexThe header is usually set in server configuration. This nginx example applies it to every PDF:
location ~* \.pdf$ {
add_header X-Robots-Tag "noindex, noarchive";
}The critical interaction with robots.txt
A crawler can only obey a meta tag or header if it fetches the page. If robots.txt blocks the URL, the crawler never sees the directive.
This produces a common mistake. A site owner wants a page out of search results, adds Disallow to robots.txt, and also adds noindex to the page. The noindex is never read. Search engines may still list the URL, without a snippet, because other sites link to it.
To remove a page from an index, allow crawling and serve noindex. To stop a crawler from fetching a page at all, use robots.txt. These are different goals, and the right choice depends on which one you actually have.
What these directives mean for AI
The directives above were designed for search engines. They control indexing, snippets, and caching. They were not designed to say "do not use this page to train a model." That is a different question, and there is no universal directive for it in these two mechanisms.
Some crawler operators have attached AI-related meaning to specific tokens. Treat each as a vendor claim to verify in the vendor's current documentation, not as a standard:
noindexon a page is generally understood to keep it out of that operator's search index. It is not a documented opt-out from model training for every operator.nosnippetandmax-snippetlimit how much text a search engine shows. Google has said these controls also affect how content is used in some AI search features. Confirm this against Google's current documentation before relying on it.- Some vendors have proposed or used extra tokens such as
noaiandnoimageai. These are not part of any standard, and there is no broad evidence that major crawlers honor them. Adding them costs little but should not be counted as protection.
For training opt-outs, the reliable route today is the crawler's user-agent token in robots.txt. For rights reservations that travel with the document, see the TDMRep header, covered in a later chapter.
Advisory, like robots.txt
Both mechanisms rely on the crawler choosing to obey them. A crawler that ignores robots.txt will also ignore a meta tag. Neither mechanism authenticates a visitor or blocks a request.
There is one practical difference. A noindex directive does reduce risk for well-behaved search engines, because it removes a page they would otherwise list. It does not prevent anyone from reading the page. If a page contains private information, use authentication, not a meta tag.
Checking your headers
You can check what your server sends with curl. The -I flag sends a HEAD request and prints only the headers.
curl -sI https://example.com/report.pdf | grep -i "x-robots-tag"Some servers answer HEAD and GET differently, so confirm with a GET request when the result looks wrong:
curl -s -D - -o /dev/null https://example.com/report.pdf | grep -i "x-robots-tag"To read a page's meta robots tag in Python:
import urllib.request
from html.parser import HTMLParser
class RobotsMetaParser(HTMLParser):
def __init__(self):
super().__init__()
self.directives = []
def handle_starttag(self, tag, attrs):
if tag != "meta":
return
attrs = dict(attrs)
name = (attrs.get("name") or "").lower()
if name in ("robots", "googlebot"):
self.directives.append((name, attrs.get("content", "")))
url = "https://example.com/"
with urllib.request.urlopen(url) as response:
header = response.headers.get("X-Robots-Tag")
html = response.read().decode("utf-8", errors="replace")
parser = RobotsMetaParser()
parser.feed(html)
print("X-Robots-Tag:", header)
print("Meta tags:", parser.directives)Common errors
- Blocking and noindexing the same URL. The crawler never fetches the page, so it never reads
noindex. Remove theDisallowrule if you want the directive to work. - Putting the meta tag in the body. Crawlers expect it in
<head>. A tag injected later by JavaScript may be missed by crawlers that do not render scripts. - Assuming the header exists on every route. CDNs, proxies, and caches can strip or override headers. Test the public URL, not only the origin server.
- Conflicting directives. A page with
indexin a meta tag andnoindexin a header leaves the outcome to each crawler's rules. Most apply the most restrictive one, but do not depend on it. - Treating a directive as security. These signals describe your preference. They do not hide or protect content.
- Using non-standard tokens as protection. Tokens like
noaihave no documented broad support.
Where this fits in your decision
Use these directives when you need to control one document or one file type, and when the audience is search engines that document their behavior. Use robots.txt for crawl access and AI crawler tokens. Use enforcement for hard requirements. Meta and header directives do not replace any of these, and llms.txt does not replace them either.
Exercise
You add Disallow: /private-report.pdf to robots.txt and also serve X-Robots-Tag: noindex for that file. The URL still appears in search results with no snippet. Why, and how do you fix it if your goal is to remove it from results?
Show answer
The robots.txt rule stops the crawler from fetching the file, so it never sees the noindex header. The search engine still knows the URL from links on other sites and can list it. To remove it, delete the Disallow rule so the crawler can fetch the file and read noindex. Once the URL has dropped from the index, you can decide whether to block crawling again. If the file is confidential, put it behind authentication instead.
Exercise
A colleague says that adding <meta name="robots" content="noindex"> to every page will stop AI companies from training on the site. Give two reasons this is not reliable.
Show answer
First, noindex is a search-index directive and is not documented as a training opt-out by every operator. Second, it is advisory and only read by crawlers that fetch the page and choose to honor it. A crawler that ignores robots.txt will ignore it too. For training opt-outs, use the operator's documented robots.txt token. For hard requirements, use enforcement such as bot verification, WAF rules, or authentication.
Exercise
Why is X-Robots-Tag the right tool for keeping PDF files out of search results, when a meta robots tag is not?
Show answer
A PDF has no HTML <head>, so there is nowhere to put a meta tag. The X-Robots-Tag header is sent with the HTTP response and works for any file type. You can apply it to all PDFs at once in the server configuration.