Redirect www domain alias to naked domain alias

Hello,

I am using Netlify DNS for domain-a.com and domain-b.com, both of which are the same Netlify app. My goal is to redirect www.domain-a.com to domain-a.com, and www.domain-b.com to domain-b.com.

Currently I have domain-a.com as my “primary” domain, and www.domain-a.com was automatically configured to redirect to domain-a.com (it says “Redirects automatically to primary domain” on my setting page).

I added both domain-b.com and www.domain-b.com as “Domain aliases” for domain-a.com. I would like the same behavior as domain-a.com, specifically www.domain-b.com should redirect to domain-b.com.

I found this page in the docs which says to create a _redirects file to the root of my site, presumably with this content:

http://www.domain-b.com/* https://domain-b.com/:splat 301!
https://www.domain-b.com/* https://domain-b.com/:splat 301!

Is it possible to achieve my desired redirect by modifying my Netlify DNS settings, or must I add the _redirects file? I didn’t have to add the _redirects file to handle my primary domain, so can I do the same for my alias?

Thanks!
David

You must add the redirects file. The special automatic handling for www/bare domain ONLY applies to the primary domain. We treat every other name (aka domain alias) the same, with no special handling beyond getting added to your SSL certificate.

That redirect looks like what I’d recommend to you if you wrote in to the helpdesk. Make sure it goes above any other redirect such as the one for single page apps (https://www.netlify.com/docs/redirects/#history-pushstate-and-single-page-apps)

1 Like

Sounds good, thank you for your quick response!

1 Like