Indexing

X-Robots-Tag

X-Robots-Tag is an HTTP response header that provides the same indexing directives as the robots meta tag but can be applied to any file type, including PDFs, images, videos, and API responses.

The robots meta tag only works in HTML documents. For non-HTML resources (PDFs, images, JSON files), use the X-Robots-Tag HTTP header to control indexing. Directives are the same: `noindex`, `nofollow`, `nosnippet`, `noarchive`, etc.

Common use cases: preventing indexing of PDF documents that contain duplicate content, blocking indexing of image files that should not appear in Google Images, and preventing API endpoints from being indexed. You can also target specific crawlers with `X-Robots-Tag: googlebot: noindex`.

In Next.js, set X-Robots-Tag via the `headers()` function in `next.config.js` or in middleware. This is particularly useful for PDF downloads, API routes, and static assets that should not be indexed.

Example

// next.config.js — X-Robots-Tag for non-HTML resources
module.exports = {
  async headers() {
    return [
      {
        source: "/api/:path*",
        headers: [
          { key: "X-Robots-Tag", value: "noindex, nofollow" },
        ],
      },
      {
        source: "/downloads/:path*",
        headers: [
          { key: "X-Robots-Tag", value: "noindex" },
        ],
      },
    ];
  },
};

Stop shipping broken SEO

Indxel validates your metadata, guards your CI/CD pipeline, and monitors indexation — so you never miss an SEO issue again.