WordPress explained

X-Robots-Tag

  • 5 min read
  • Term 130 of 143
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

The X-Robots-Tag is an HTTP response header that tells search engines whether they may index a URL and show it in search results, for example X-Robots-Tag: noindex. It does the same job as the meta robots tag, but because it is sent by the server, it also works for PDFs, images and other files that are not HTML pages.

You will mostly use it to keep files like PDFs out of Google, or to apply one rule to a whole group of URLs at once. Below I show you the syntax, the most useful directives, and how to set it up on Apache, Nginx and WordPress.

X-Robots-Tag syntax and examples

The header is part of the HTTP response your server sends before the content. A response for a PDF that should not be indexed looks like this:

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

You can combine several directives in one header, separated by commas. You can also target one crawler by putting its name in front, or send more than one X-Robots-Tag header:

X-Robots-Tag: googlebot: nofollow
X-Robots-Tag: otherbot: noindex, nofollow
X-Robots-Tag: max-snippet:50, max-image-preview:large

Without a crawler name, the rule applies to all search engines that support it.

X-Robots-Tag directives

  • noindex: do not show this URL in search results.
  • nofollow: do not follow the links on this page.
  • none: the same as noindex, nofollow.
  • noarchive: do not show a cached copy. Google removed its cache links in 2024 and no longer uses this rule, but other search engines such as Bing still support it.
  • nosnippet: do not show a text snippet or video preview in the results.
  • max-snippet:[number]: limit the snippet to this many characters. 0 means no snippet, -1 means no limit.
  • max-image-preview:[setting]: the largest image preview allowed: none, standard or large.
  • max-video-preview:[number]: the maximum number of seconds of a video preview.
  • noimageindex: do not index the images on this page.
  • unavailable_after:[date]: stop showing the URL after this date, for example unavailable_after: 2027-06-30. Google accepts common date formats such as ISO 8601.

X-Robots-Tag vs meta robots vs robots.txt

These three are often mixed up, but they do different things:

  • Meta robots tag: a tag in the <head> of an HTML page. Controls indexing and snippets. Only works on HTML pages. This is what SEO plugins set when you tick “noindex”.
  • X-Robots-Tag: an HTTP header. Same directives as the meta robots tag, but works for any file type and can be set for many URLs at once with one server rule.
  • Robots.txt: a file in the root of your site. Controls crawling, not indexing. A URL blocked in robots.txt can still show up in Google if other sites link to it.

So if you want a URL out of the search results, use noindex (meta tag or X-Robots-Tag). If you want to save crawl effort on URLs that do not matter, use robots.txt. Read more about how this works on my page about indexing.

How to set the X-Robots-Tag

Apache (.htaccess)

Most shared hosting runs Apache or a compatible server. Add this to the .htaccess file in the root of your website to noindex all PDF files. It needs the mod_headers module, which almost every host has enabled.

<IfModule mod_headers.c>
  <FilesMatch "\.pdf$">
    Header set X-Robots-Tag "noindex, nofollow"
  </FilesMatch>
</IfModule>

Nginx

On Nginx you add the header inside the server block of your site configuration and reload Nginx:

location ~* \.pdf$ {
    add_header X-Robots-Tag "noindex, nofollow";
}

PHP and WordPress

In PHP you send the header before any output. In WordPress you can do that with a small snippet, for example with the Code Snippets plugin. This one noindexes your internal search result pages:

add_action( 'template_redirect', function () {
    if ( is_search() ) {
        header( 'X-Robots-Tag: noindex, follow', true );
    }
} );

For normal pages and posts you do not need code. Your SEO plugin sets the meta robots tag for you, and that is simpler. Use the X-Robots-Tag for files, downloads and server-wide rules.

How to check the X-Robots-Tag

  1. Browser DevTools: open the URL in Chrome, press F12, go to the Network tab, reload, click the first request and look under Response Headers.
  2. curl: run this in your terminal and look for the X-Robots-Tag line.
curl -I https://example.com/files/brochure.pdf
  1. Google Search Console: paste the URL into the URL Inspection tool. Under page indexing it tells you if indexing is allowed and if a noindex was found in the X-Robots-Tag header.

Common mistakes

  • Blocking the URL in robots.txt as well. If Google cannot crawl the URL, it never sees the noindex header, so the URL can stay in the results.
  • A rule that matches too much. A wrong pattern can noindex your whole website. Always test a few normal pages after a change.
  • A forgotten noindex from a staging site. Check your live site headers after a migration.
  • Cached responses. A caching plugin or CDN can keep serving old headers. Clear the cache after you change them.
  • Expecting instant results. Google has to recrawl the URL before a new noindex takes effect.

Frequently asked questions

What is the difference between a robots tag and the X-Robots-Tag?

The robots tag, or meta robots tag, sits in the HTML of a page. The X-Robots-Tag is sent as an HTTP header. They support the same directives, but only the X-Robots-Tag works for files like PDFs and images.

Does the X-Robots-Tag help my SEO?

Not directly. It does not make pages rank higher. It helps you keep thin or private files out of Google, so your search results show the pages you actually want people to find.

Can I use the X-Robots-Tag and the meta robots tag together?

Yes. If they conflict, Google follows the most restrictive rule. To keep things simple, use one method per URL.

Related: Robots.txt, Indexing, Technical SEO

Ferdy.com

Learn more about X-Robots-Tag

Want to see this in practice? These free tutorials show it step by step:

Want AI to do the work? Use the free SEO and AI search optimization prompt.

Still stuck?
Watch along

Most questions are easier when you see them on screen. Find the tutorial for your problem and follow along.

Black Friday A full year of Hostinger web hosting + free domain for about $30 with coupon code FERDY1 year hosting + free domain: about $30 with code FERDY Ends Dec 14 Get the deal Ad