deindexpages.com
Core methods

The X-Robots-Tag HTTP header, explained

The X-Robots-Tag is an HTTP response header that carries the same indexing rules as the robots meta tag. It is the only practical way to noindex files that have no HTML head, and it lets you apply rules to whole directories or file types at the server level.

Same rules, different transport

The Google guide to blocking indexing says the robots meta tag and the X-Robots-Tag header have the same effect, so you choose whichever suits your site and content type. The header form is also the one that works for non-HTML files such as PDFs, videos and images.

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

The accepted values mirror the meta tag, including noindex, nofollow, none and unavailable_after. The robots meta tag and X-Robots-Tag specification lists them all. You can target a specific crawler by prefixing it, for example X-Robots-Tag: googlebot: noindex.

When to prefer the header

SituationMeta tagHeader
Normal HTML page you can editGoodGood
PDF, DOCX, image, video, audioImpossibleThe only option
Hundreds of pages in one directoryNeeds template changeOne server rule
Staging or preview environmentEasy to forget on deployCan be applied host-wide
Hosted platform with no server accessOften possibleOften impossible

Apache examples

With mod_headers enabled, in the server config or .htaccess:

<FilesMatch "\.(pdf|docx?)$">
  Header set X-Robots-Tag "noindex"
</FilesMatch>

To apply to everything under a directory, place a .htaccess file in that directory with Header set X-Robots-Tag "noindex".

Nginx examples

location ~* \.(pdf|docx?)$ {
    add_header X-Robots-Tag "noindex" always;
}

Note that add_header directives are inherited only if the current block defines none of its own. If a nested location adds another header, repeat the robots header there too.

Application and CDN examples

The crawl requirement still applies

A header is only read when the crawler fetches the file. If robots.txt blocks the PDF or directory, Google never receives the header. The result: the URL can remain listed with no description. This is the same trap that affects the meta tag, covered in why robots.txt does not deindex.

Check the final response your users and crawlers get, not your origin server. Reverse proxies, CDNs and security plugins may strip or overwrite response headers.

How to test the header

  1. Run curl -I https://example.com/files/report.pdf and look for x-robots-tag: noindex. Header names are case-insensitive.
  2. Confirm the status is 200. A noindex header on a 404 or 301 response is moot.
  3. Test a few URLs from the pattern you targeted, not just one, to catch regex mistakes.
  4. Inspect a representative URL in Search Console. The URL Inspection tool shows whether indexing is allowed and what Googlebot fetched.
  5. Track the URLs in the Page indexing report. Files with the header should move to "Excluded by 'noindex' tag" after recrawling.

Common mistakes

Header or removal tool?

The header is durable but slow. The Removals tool is fast but temporary. If a document is exposing something sensitive, hide the URL first through the Removals tool and then fix the file: delete it, protect it, or serve the header. Deleting the file and returning a 404 is the cleanest outcome. See 404 vs 410.

Choosing between header and tag on a normal page

For ordinary HTML pages, either works, but pick one place to manage the rule and stick with it. Many teams use the header at the edge or server for rules that apply by path or file type, and use the meta tag only where a CMS user must toggle a single page. Mixing both on the same URL is allowed, but it makes debugging harder, because you must check two places to know the effective rule. Document where each kind of rule lives so that the next person who changes the site knows where to look.

Frequently asked questions

Is X-Robots-Tag as strong as the meta tag?

Google says they have the same effect. Use the header for non-HTML resources and for rules applied by pattern.

Can I set X-Robots-Tag in robots.txt?

No. It is an HTTP response header, set by your server, application or CDN.

Why does my header not show up in curl?

Another layer may be overwriting it, the rule may not match the URL, or your cache is serving an older response. Test the origin directly, then purge the cache.

Does it work on images used in pages?

Yes, if the image file response carries the header and the image is crawlable. See removing images from Google.