Using one domain per branch

Hello,

I’ll be using fake build name and fake domain names in that post on purpose. The real domain names are part of an online treasure hunt and I don’t want to share the links here. Happy to provide them to support in private, though.

Last week I deployed a treasurehunt project to Netlify. I configured the custom domain alpha.com to point to it. It worked really well.

Now this week I need to build another treasure hunt, with very similar content, but on a different domain name (beta.com). I enabled branch deploys on my account, created branches alpha and beta. This gave me access to alpha--treasurehunt.netlify.com and beta--treasurehunt.netlify.com domains.

I went to my treasurehunt project and removed alpha.com from the custom domains. I then went to my alpha.com domain and added a new ALIAS to alpha--treasurehunt.netlify.com. I expected this to now correctly point alpha.com to the branch deploy.

But this does not seem to be working (all I have is a blank page with Not found), and I wonder if this is because I still have two NETLIFY entries in my DNS panel as shown here:

Is this the right way to have several domains pointing to different branches of the same project?

@pixelastic, at this time the only way to link a custom domains to a Netlify site is by the automatic creation in the form of “branch name” + “primary custom domain name”.

If the site’s primary custom domain is example.com and the branch name is “branch-1” then the automatic custom domain will be branch-1.example.com. This same limitation applies to sites using external DNS instead of Netlify DNS as well. The naming convention above must be followed.

If you want to have a custom domain link to a branch of a site, that branch must be the production branch for the site.

So, using the example above, you would make a new Netlify site linked to the same Git repo as “treasurehunt” but where the production branch for the site was the branch “alpha”. One this was done, then add the domain as the custom domain for this Netlify site.

Again, at this time, there is no way to add arbitrary custom domains to the branch subdomains of single Netlify site.

Thanks for the info.

I think I was over-engineering this. Creating a new Netlify website and targeting the correct branch (thus making it the production branch for that website) actually made linking it to a custom domain all the simpler.

Thanks for the tips

1 Like