Branch deploys not working when _not_ using Netlify DNS

Hey,
We own the brandtotal.com domain, and want to point https://staging.brandtotal.com to https://staging--brandtotal-www-frontend.netlify.app.

I followed [Support Guide] How to use Netlify’s branch deploy feature without Netlify DNS, and everything seems to be in place, but the last step requires contacting your technical support. I already sent an email 2 days ago via the Contact Form (we’re on the Pro plan), but didn’t receive any response as of now.

The configuration we want is that master will be our production branch - and will be available via https://app.brandtotal.com, which will be CNAME-ed (on our end) to brandtotal-www-frontend.netlify.app (this is not in place yet, we want to move to that, but can’t until we verify that staging works - see below).
Next, we want our staging branch to be available via https://staging.brandtotal.com, which is already CNAME-ed to staging--brandtotal-www-frontend.netlify.app:

The site name is brandtotal-webapp-frontend.

Thanks

P.S.
We don’t want to transfer the nameservers to point to Netlify’s ones, as we have more stuff on brandtotal.com that aren’t related to Netlify at all, and don’t want to mix unrelated stuff. We just want these 2 subdomains to work as described above.

Hi, @bengry. The branch subdomain must be the subdomain of the primary custom domain for this site for this feature to work.

In this case, the primary custom domain is not brandtotal.com and this can be confirmed (only with an authorized login) here:

https://app.netlify.com/sites/brandtotal-www-frontend/settings/domain#custom-domains

If you add the subdomain of staging under the primary custom domain listed on the page above, we can extend the SSL certificate. If there are other questions or if/when the record has been created for the primary custom domain, please let us know.

Hey @luke. So you suggest I add brandtotal.com under “Custom domains”? If so wouldn’t that cause someone going to https://brandtotal.com (or https://www.brandtotal.com) to get to our master branch? (https://brandtotal-www-frontend.netlify.app/)?

Or am I missing something?

Just to reiterate - I only want the 2 subdomains - staging.brandtotal.com and app.brandtotal.com to redirect to Netlify. If I have something like blog.brandtotal.com for example, it should have no connection to Netlify whatsoever.

What I was able to do, is to put staging.brandtotal.com in the Custom domains list here: Netlify App, then set up my “Production branch” to staging (in Netlify App), but that means that for production (i.e. master branch <-> https://app.brandtotal.com) I’ll need to create a separate Netlify website, using a similar technique. This seems quite cumbersome and means I have to maintain the settings of 2 websites, one of which only builds the production branch, but still…

Hi, @bengry. For the branch subdomain feature, it only works for subdomain under the “primary custom domain” for the site at Netlify.

For this site, you have the primary custom domain set to be app.brandtotal.co. So the branch subdomain would need to be stating.app.brandtotal.co. If you want the staging branch subdomain to be another name, then you will need to change primary custom domain to match.

There is the workaround you mention. You can make the branch in question the production branch for the same repo but linked to a new site. This will allow you to pick any custom domain you want (because the name is now the production branch name and there are no restrictions to the production branch). This restriction of having the branch subdomain under the primary custom domain only applies for our branch subdomain feature.

If there are other questions, please let us know

Sounds like we’ll have to go with the 2 websites route then if we want to stick with our current naming of the domains (app.brandtotal.com and staging.brandtotal.com). However, since they’re both connected to the same git repo, and use the same netlify.toml, part of which includes stuff like reverse proxy to our backend:

[[redirects]]
from = "/api/*"
to = "https://staging-website.herokuapp.com/api/:splat"
status = 200
force = true

How can I set it up such that with the same toml I get different redirects based on the branch? Since with deploy contexts I can only go so far, given that 2 I have sites - one which has staging as its production branch and one which has master as its production branch.

For all other stuff I think I can manage with just having the same environment variable set up in the Netlify GUI for each site, such that for example SENTRY_ENVIRONMENT is different in each site, and then the plugin is configured in the toml and “just works” with whatever is in its current site, but I’m not sure I can set up redirects based on that etc.

Easiest thing to do for separate redirects is to have them in a _redirects file, one for each site, either copied in to the repo with a bash script during the build or in each site’s folder structure (depending on how it’s structured)!