Redirect subdomain

Hello,

I have multiple domains that will access my site on netlify.

I chose this route over creating multiple netlify sites to prevent duplication of functions running, ENV vars, etc.

When adding a second domain to my domain list I would like to redirect all additional apex domains to their www. counterpart.

domain1.comwww.domain1.com (works with default site domain)

How would I redirect domain2.com to www.domain2.com? I don’t see any domain redirect options and the “redirects” file seems to only redirect paths.

Thoughts?

I have tried adding a redirect rule to netlify.toml without any luck:


[[redirects]]
from = “https://domain.com/
to = “https://www.domain.com/
status = 301
force = true

Using redirects is the correct option.

If example.com is the primary domain www.example.com will automatically redirect to it. If you then wanted to add example.net and example.org (including the www) to redirect to example.com in a netlify.toml file you would need to add

E.g.

[[redirects]]
  from = "https://example.net/*"
  to = "https://example.com/:splat"
  status = 301
  force = true

[[redirects]]
  from = "https://www.example.net/*"
  to = "https://www.example.com/:splat"
  status = 301
  force = true

[[redirects]]
  from = "https://example.org/*"
  to = "https://example.com/:splat"
  status = 301
  force = true

[[redirects]]
  from = "https://www.example.org/*"
  to = "https://www.example.com/:splat"
  status = 301
  force = true

In a _redirects file you would add

https://example.net/*    https://example.com/:splat    301!
https://www.example.net/*    https://example.com/:splat    301!
https://example.org/*    https://example.com/:splat    301!
https://www.example.org/*    https://example.com/:splat    301!