I have two domains on an app. Can I set domainB.com to redirect to domainA.com in fly.io, or should I do that in DNS records?

I have one fly.io app with multiple domains (got a second domain as branding evolved.)

domainA.com
domainB.com

Both successfully load the site, but if a user visits domainB.com, I want them to be redirected to domainA.com (for branding purposes and clarity).

Is that something I should handle on fly.io or on the DNS side?

The most common way to handle this would be to have everything use an HTTP 301 redirect.

To have your app itself handle this, you’ll want to modify it so that every request for domainB.com is 301 redirected to domainA.com. You’d likely be able to find information by googling X 301 redirect where X is your framework or application.

If having the application itself process the redirect is cumbersome, you could setup a second app that just runs nginx and provides the redirects. You’d then remove the certificate for domainB.com from the first app, and add it to the second app. The section The return Directive in this nginx blog post describes a method for this and you can find the official docker image for nginx here.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.