Hi, I’m having trouble getting custom headers working, I’m setting them in the netlify.toml file, but no matter what I try they don’t seem to come through. I’m currently using the example from the custom headers docs.
So I agree, these headers are not present. If I use http:// not https:// I see the headers, however when it does the redirect to https:// they are missing.
In an attempt to reproduce this, I deployed a basic site (using drag and drop, and deploy from git) with the same headers in a netlify.toml and also in _headers (instead of the toml) and in both cases I see the headers present regardless of accessing http:// (including on the redirect) or https://(these headers don’t appear by default on Netlify as far as I know.)
Do you have other headers present?
Is the netlify.toml in the root of the git repository or deploy directory (if using drag and drop)?
If you put them in the _headers file instead of netlify.toml do you see the same behaviour?
If you deploy to a new site, do you see the same behaviour?
So I’ve tried switching to a _headers file instead of using the netlify.toml and I get the same result. the headers only appear on the 301 redirect. I tried creating a new site and deploying to that, but get the same result as the other site. Headers are not shown on https.
Save a plain text file called _headers to the publish directory of your site
The _headers file is in the root of the project so does not make it into the publish directory (build in this case) so the headers never get processed. if you move the _headers file into the static directory, it is copied to the output (build) directory during build, and Netlify will the process the headers.
If you wanted to use the netlify.toml (as you have this file) to specify [[headers]] this remains in the root of the project.
Hi, @darrenjansson. I can solve the mystery for why the headers were not working for the deploy 61b3bd5ea5a0cf000741b0c5. The explanation is the first limitation listed here:
Custom headers apply only to files Netlify serves from our own backing store. If you are proxying content to your site or dealing with a URL handled by a function, custom headers won’t be applied to that content. In those cases, the site being proxied to or the serverless function should return any required headers instead.
The root path / was being handled by a function for that specific deploy. Because the function was replying, the function itself must be the source of any custom headers. The header rules in netlify.toml or _headers will never apply to a function response.
If there are other questions about this, please let us know.