Netlify does not send custom headers in a redirect file (using https in the "to")

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:

[[redirects]]
from = “/ab”
to = “https://zerotousers.com/”
headers = {X-Frame= “Netlify543”}

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.

What could be the issue?:

Do you have asset optimisation enabled? I think custom headers only work without Asset Optimisation.

Yes I have, but I’d like to keep those settings (like pretty URLs). I see no reason why asset optimization settings would interfere with sending custom headers.

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.

Can someone from Netlify confirm this?

It has been mentioned a few times as far as I can see but it would be good if it was explicitly in the docs. I’ll tag @perry for you to get a Netlify employee’s response for you :slight_smile:

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.

thanks for letting us know. We’ll get some :eyes: on this and evaluate.

Please do. I’ve been trying to get an answer for this for over a month.

Hiya @darkomkd and sorry for the delay! There is no way to process only certain URL’s; the asset optimizations are all or nothing.

However, even with NO asset optimization, we still serve your content at pretty URL’s! We’ll automatically serve:

site.com/file.html

as

site.com/file

and also

site.com/directory/index.html

as

site.com/directory

EVEN if you have processing off.

What Pretty URL’s does (in addition) is:

  1. rewrite your content to REFER to those paths
  2. upload that transformed content to cloudfront (our optimized asset CDN provider)
  3. where you cannot apply custom headers to the assets.

I’ll talk with our documentation team about where to best add these limitations to the docs, but hopefully that gives you a path forward.

Tried this. Disabled assets. Here is the redirect URL. . Still doesn’t work.

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:

[[redirects]]
  from = "/abc"
  to = "https://zerotousers.com"

[[headers]]
  for = "/abc"
  [headers.values]
    X-From = "Netlify"

This returns the 301 response but with the “x-from: Netlify” header. If there are other questions, please let us know.