Why use a header instead of a meta tag?#
The meta robots tag only works inside HTML. PDFs, Word documents, images and feeds can’t contain it — the X-Robots-Tag header can. It’s also handy for applying rules to many files at once at the server level.
Examples#
Response header for a single file:
X-Robots-Tag: noindex, nofollow
Apache (.htaccess) — noindex all PDFs:
<FilesMatch ".pdf$">
Header set X-Robots-Tag "noindex"
</FilesMatch>
Nginx:
location ~* .pdf$ {
add_header X-Robots-Tag "noindex";
}
Target a specific bot: X-Robots-Tag: googlebot: noindex.
Tips#
- It supports the same directives as meta robots (noindex, nofollow, nosnippet, max-image-preview…).
- The file must be crawlable — don’t block it in robots.txt.
- Check headers with DevTools (Network tab) or
curl -I https://example.com/file.pdf. - Staging sites can send
X-Robots-Tag: noindexsitewide as a safety net (plus password protection).
Related: noindex, robots.txt.