Get the website domain

Hey I want to pass my host www.example.com as a header in the redirect

I want to be able to redirect www.example.com if query param version=10 to www.example2.com and adding X-ORGINAL-HOST = www.example.com as a header.

Hey there, can you share what you’ve tried so far- a _redirects file or netlify.toml? Have you checked out our docs and found that something didn’t work as expected?


Having a bit more info will help us troubleshoot with you.

We are using this for a Whitelabel feature for our customer as every customer has his own domain.
Right now I can do it only with one domain by hard coding the origin in the api I’m redirecting to like this.

/* https://some.api.dev/:splat 200

I want to be able to redirect the user from example.com or example2.com or example3.com to

https://some.api.dev/:splat with a header of X-ORGINAL-HOST = www.example.com for example.

without hardcoding them like this

[[redirects]]
  from = "www.example.com/*"
  to = "https://some.api.dev/:splat"
  status = 200
  force = true
  headers = {X-ORGINAL-HOST = "www.example.com"}
[[redirects]]
  from = "www.example2.com/*"
  to = "https://some.api.dev/:splat"
  status = 200
  force = true
  headers = {X-ORGINAL-HOST = "www.example2.com"}
[[redirects]]
  from = "www.example3.com/*"
  to = "https://some.api.dev/:splat"
  status = 200
  force = true
  headers = {X-ORGINAL-HOST = "www.example3.com"}

What I want to do is get the domain and add it in the redirect headers.

maybe something like this

[[redirects]]
  from = "https://:domain/*"
  to = "https://some.api.dev/:splat"
  status = 200
  force = true
  headers = {X-ORGINAL-HOST = ":domain"}

Hi, @hadyrashwan. There is no other way to do this at this time. There is no way to capture the domain name used in the request to be reused in the redirect.

The only workaround is what you are already doing: to match the domain in the rule itself and, therefore, know the domain name being used in that way.

If there are other questions about this, please let us know. We can also file a feature request asking for this if you would like us to do so.