X-Robots-Tag for Non-HTML Resources - Control Indexing Without Confusing It with Access
A website may offer a PDF that people should be able to download while still preferring that the file not appear as a separate search result. An HTML page can carry a robots meta element in its <head>, but a PDF has no HTML head. The response itself needs to carry the instruction.
X-Robots-Tag fills that gap. It can attach an indexing rule such as noindex to an HTTP response, including a response for a PDF, image, or generated file. The mechanism is small; choosing where to use it is not. It only makes sense after separating three questions that are often collapsed into one: may a crawler fetch this URL, may a search engine show it in results, and may this requester access it at all?
Three controls, three different jobs
Crawling is the act of requesting a resource. The Robots Exclusion Protocol in RFC 9309 defines rules in robots.txt for controlling crawler access to URI paths. The RFC is explicit that these rules are not access authorization.
Indexing is a search system's decision about whether a URL or its content may be stored and made eligible for search results. A robots meta element or an X-Robots-Tag response header communicates rules to search crawlers that support them. MDN describes the header as a de-facto convention rather than part of a current specification, so support must not be assumed to be identical everywhere.
Authorization is the server's decision to return the resource to a requester. If a file contains private invoices, backups, customer exports, or unpublished material, the relevant controls are authentication, authorization, and perhaps removing the file from a public location. Neither robots.txt nor X-Robots-Tag makes a public URL secret.
This distinction gives a useful rule of thumb: use an indexing directive for public material that should not be a search result; use real access control for material that should not be public.
Why put the rule in an HTTP header?
For an HTML document, these two forms have the same basic noindex purpose for Google:
<meta name="robots" content="noindex">
HTTP/1.1 200 OK
Content-Type: application/pdf
X-Robots-Tag: noindex
The first form lives inside HTML. The second is response metadata, so it also works where no HTML element can be inserted. Google's robots tag documentation specifically recommends the header form for non-HTML resources such as PDF, video, and image files.
The header is not limited to noindex. Supporting crawlers may understand directives related to links, snippets, previews, translation, or availability after a date. Those controls are partly vendor-specific and can change. A conservative implementation starts with the smallest rule required and checks the documentation of the search engines that matter, instead of treating every published directive as universal.
It is also possible to target a named crawler or send multiple fields. That flexibility can become difficult to audit. If the policy really is “do not index this resource,” the unqualified field is easier to read:
X-Robots-Tag: noindex
The robots.txt trap
A crawler cannot obey a response header it never receives. Google states that robots meta rules and X-Robots-Tag rules are discovered when a URL is crawled. If robots.txt disallows that URL, Googlebot cannot fetch the response and therefore cannot see its noindex field.
This produces a configuration that looks strict but defeats its own indexing instruction:
# robots.txt
User-agent: *
Disallow: /downloads/internal-catalog.pdf
# Response that the blocked crawler cannot retrieve
X-Robots-Tag: noindex
Google's robots.txt guide explains why the distinction matters: a disallowed page URL can still appear in results when it is discovered through links, even though the crawler does not read its content. Its separate noindex guide therefore requires the resource to remain accessible to the crawler so the rule can be observed.
For a public PDF that should remain downloadable but not indexed, the usual model is to allow crawling and return X-Robots-Tag: noindex. For a private PDF, the model is to require authorization. Combining a public URL, a robots disallow rule, and a hidden hope that nobody finds the link is not an access-control design.
Apply the rule at the layer that owns the policy
A narrowly scoped server rule can suit a known static file. In NGINX, an exact location avoids accidentally applying the policy to every PDF:
location = /downloads/internal-catalog.pdf {
add_header X-Robots-Tag "noindex" always;
}
The official ngx_http_headers_module documentation records two details worth checking before deployment. Without always, add_header applies only to a documented set of response statuses. Header directives are also inherited from a higher configuration level only when the current level defines no add_header directives. The example uses always deliberately, but that does not remove the need to inspect other headers and the final response.
A broad expression such as “all files ending in .pdf” may be convenient, but it also hides useful public reports, manuals, or downloadable articles from supporting search engines. Scope should follow content policy, not merely a filename extension. Exact locations, a dedicated directory with a clear purpose, or application metadata are often easier to review.
When the application decides which generated document is public but non-indexable, PHP can emit the field with the response:
<?php
header('Content-Type: application/pdf');
header('X-Robots-Tag: noindex');
readfile($documentPath);
The PHP manual notes that header() must run before output is sent. The example only demonstrates response construction. In a real download handler, $documentPath must come from trusted application logic with authorization and path validation handled separately.
Verify the delivered response, not just the configuration file
A correct-looking source file is one layer of evidence. The useful check is the response that leaves the complete stack:
curl -sS -D - -o /dev/null \
https://example.com/downloads/internal-catalog.pdf
Inspect the final status, Content-Type, and every X-Robots-Tag field. If the URL redirects, inspect the whole redirect path and the final resource rather than assuming the first response describes the destination:
curl -sSL -D - -o /dev/null \
https://example.com/downloads/internal-catalog.pdf
This can expose several mistakes: the header appears only on an intermediate redirect; an application and reverse proxy emit conflicting values; a CDN serves an older cached response; or a more specific NGINX location does not inherit the expected header. Multiple fields are allowed, but simplicity is easier to reason about. Google's documentation says that when its supported rules conflict, the more restrictive rule applies; that should not be generalized into a promise about every crawler.
A header check proves only what the server delivered at that moment. It does not prove that a search engine has recrawled the URL, interpreted the rule, or removed an existing result. Google notes that revisiting can take time and recommends URL Inspection and the Page Indexing report for observing Google-specific processing. There is no honest fixed removal time to promise.
Status codes still carry their own meaning
X-Robots-Tag should not compensate for a misleading HTTP status. A document that no longer exists should normally return an appropriate 404 or 410, not a successful placeholder with noindex. A resource that requires login should enforce that requirement. A duplicate public document may need a canonicalization or redirect decision rather than being hidden by default.
These mechanisms answer different questions. The status describes the outcome of this HTTP request. Authorization controls access. A canonical signal identifies a preferred representative among duplicates. An indexing rule asks a cooperative search crawler not to show a resource. Keeping those meanings separate produces configurations that are easier to debug and less likely to conceal a content-model problem.
A small decision checklist
- Is the resource genuinely public? If not, stop and add authorization rather than a robots rule.
- Should the URL remain available to people but stay out of supporting search results? Consider
noindex. - Can the resource contain an HTML
metaelement? If not, use the response header. - Is the URL crawlable so a crawler can actually receive the rule?
- Is the policy scoped to the intended resource rather than every file with the same extension?
- Have the origin, proxy, CDN, redirects, status, and final response been checked?
- Has search-engine processing been observed separately from the HTTP header check?
Conclusion
X-Robots-Tag is useful precisely because it is modest. It places an indexing instruction in the response, including for resources that cannot carry HTML metadata. It does not secure a file, prevent every crawler from fetching it, guarantee support from every search engine, or make an existing result disappear immediately.
The durable approach is to decide the policy first: access control for private material, honest status codes for missing material, and a narrowly scoped indexing rule for public material that should not be a search result. Then verify the response across the actual delivery path and leave enough room for crawler-specific behavior and recrawl delay. The header is one line; the clarity comes from not asking that line to do three different jobs.
References
- IETF / RFC Editor, RFC 9309: Robots Exclusion Protocol (September 2022)
- Google Search Central, Robots meta tag, data-nosnippet, and X-Robots-Tag specifications
- Google Search Central, Introduction to robots.txt
- Google Search Central, Block Search indexing with noindex
- MDN, X-Robots-Tag header (last modified August 21, 2026)
- NGINX, Module ngx_http_headers_module
- PHP Manual, header
