Hey guys, I’ve configured an url (which redirects to the main page as you can see). I’m using the latest version of Jekyll, and inside the root project file I have netlify.toml which basically does this:
Now, the problem here is that Netlify DOES NOT SEND the custom header. I’ve used Fiddler to inspect the header and didn’t see the custom header anywhere in the 301 response.
I thought it’s CloudFlare (disabled it) and the same problem persists. When I see the specific Netlify deploy, it writes " 1 redirect rule processed" but " No header rules processed"
I’ve basically followed the support topic on redirects and didn’t find anything wrong. This is a very simple test I wanted to do with custom headers, and everything is okay (the latest deploy says that 1 redirect was processed successfully), except this.
Could try disabling just to see if it works. Currently on my phone look around this forum I’ve seen it discussed a few times.
Quote from one of those posts:
You won’t be able to set custom headers on assets that we optimize - if you need to set custom headers on an asset (hopefully you aren’t changing the cache-control - we advise against that and it isn’t needed on our system), you’ll have to disable asset optimization and redeploy to make that work.
Oh I see, thanks. Would be curious if I can disable asset optimization only for specific URLs (and not do it site-wide) via netlify.toml. Pretty links for example are pretty useful for things like SEO.
No header in the 301 redirect response, nothing. Guys, are you sure this thing works at all? If it doesn’t, at least let me know so I can decide what to do (like switching to a dynamic solution that supports custom headers).
Hi, @darkomkd. The [redirects.headers] syntax is used for headers sent to the service being proxied to. The end user doesn’t see those headers, the other web server does. With a 301 redirect, nothing is proxied so those headers do nothing.
If you want the end user to see the headers, use the normal [[headers]] syntax with one block for the redirect and another for the headers:
from = "/abc"
to = "https://zerotousers.com"
for = "/abc"
X-From = "Netlify"
This returns the 301 response but with the “x-from: Netlify” header. If there are other questions, please let us know.
I’m trying to do precisely this and it doesn’t seem to be working…
I’m using netlify dev (from the latest email@example.com) locally, and when I try to use [[redirects]] in tandem with [[headers]] it doesn’t work?
I’m trying to say “when somebody hits the endpoint /test, redirect them to /preferences and set a cookie”. I don’t have set-cookie as the header just yet, as I’m just trying to test it. But I don’t see any custom headers coming back. Here’s my config:
from = "/test"
to = "/preferences"
for = "/test*"
X-Jim = "WORKS"
When I hit /test in the browser, I don’t see the header on the response:
for = "/test*"
X-Jim = "WORKS"
That works. It serves the /test.html file with the custom header, and the HTML file contains a <meta> redirect to /preferences. I’d prefer to be able to do it via headers though so I’m not sure if this just isn’t supported on Netlify or if I’m doing something wrong…