Add a header just for a particular branch deploy

I have a branch deploy configured just for this one branch netlify-staging (creative, I know). Now since this is a marketing site, I’m dead scared of being penalized by duplicated content from the production site. So I added this section to my netlify.toml

[context.netlify-staging]
  [[headers]]
    for = "/*"
    [headers.values]
      X-Robots-Tag = "noindex"

But what ended happening is that the X-Robot-Tag header was added to the production deployment too, which meant that we got unindexed from Google (:sob: ).

I would like to know where’s my mistake was or if what I wanted is not even possible at all.

Please and thank you.

Hi @Jiveworld,

Redirects and Headers specified in netlify.toml are site-wide and cannot be configured specifically for some contexts. So, what you’re seeing is expected behaviour.

What you can do instead is, use _headers file. You can create a _headers file with the required content, and then in the build command for your branch, you can specify the command as npm run build && cp _headers /public/_headers. Do note, you need to replace npm run build with your build command and /public/ with your publish folder.

Hope this helps.