Can the Host header be defined on a redirect?

Hi, due to some redirection issues on the target website, I would like to set the Host header with a different subdomain than the one we’re actually connecting to. Exactly what you would do with:

curl -v https://website-old.xyz.com/ -H "Host: www.xyz.com"

I’ve tried setting it in the redirection rule but it doesn’t seem to work according to the server logs:

[[redirects]]
  from = "/*"
  to = "https://website-old.xyz.com/:splat"
  status = 200
  force = false # COMMENT: ensure that we always redirect
  headers = {X-From = "Netlify", Host = "www.xyz.com"}

Can you please help me understand if this is just totally unsupported or if there’s any other way I could do it?

Thank you!

Do you mean like this? :slight_smile:

That said, we don’t support proxying to us, just an FYI. :+1:

Thanks for the reply @Scott. If I understand correctly, I can use the _headers to adjust the response headers from Netlify. In this case, I’m not looking to set response headers. Instead, I would like the proxied request to include a different Host request header. That is, the HTTP connection is established using the resolved IP from website-old.xyz.com, but the Host header will be www.xyz.com.
Btw, the proxied request is not to a Netlify host but to another server we have with an old implementation of the website :slight_smile:

Like this: Rewrites and proxies | Netlify Docs?

I’m also wondering if the Host header can be set on a proxy redirect?

Have you read through the link I posted? That shows how you can set custom request headers on proxy redirect rules.

Yes I did and I see how to send custom headers but not set the Host header, a service I am using needs to see the host header have the same domain as my websites domain. When using a reverse proxy in Netlify, the host header becomes Netlify and doesn’t work to load the content from the 3rd party service.

Sorry for the disconnect - yes, I can confirm that you CANNOT set the Host header to a custom value when we proxy. It will ALWAYS be set to the hostname we connect to (the one specified in your proxy rule), since most web services (including Netlify when it is proxied to) require this to function correctly.

Hi @fool I wanted to clarify your answer. For this example:

What would you expect the ultimate “Host” value in the header to be? “Host”: “https://website-old.xyz.com”?

Whoops! So sorry I missed this, @dot ! I’d expect: website-old.xyz.com

No worries at all! Thanks for confirming my understanding :grinning: