Support Forums

Using Branch Subdomains in Combination with Multiple Primary Site Subdomains

Site URL: https://viewyourtour.com
Netlify URL: https://your-tour-thevectre.netlify.app

Note: For this post, I had to replace .viewyourtour.com for .SITEURL because there’s a limit on how many urls you can include in a post.

I have a Netlify react site that uses the first subdomain as the argument for what info to pull from my API. They work perfectly.

Live sites include:

For internal dev/qa purposes, I’d need to be able to add my subdomain argument to the branch url. For instance, my dev ‘r-v1_1’ branch, has a url of ‘r-v1-1.SITEURL’, which is accessible but has no real value, since there isn’t a valid API argument in the url. I believe I need ‘CUSTOMSUBDOMAIN.r-v1-1.SITEURL’ to be a masked redirect to ‘r-v1-1.SITEURL’.

URLs I need include:

My DNS is controlled through Netlify. I’ve tried creating a CNAME record for ‘still-hopes.r-v1-1.viewyourtour.com’ that points to ‘r-v1-1.viewyourtour.com’ but I just continue to get a Not Found error. For funsies, I also did the same thing with an ALIAS record. No luck.

Is what I’m trying to do possible? If so, how do I do it?

Not Found error indicates the absence of an index.html. If the DNS would not have worked, that is, if the subdomain wasn’t actually working, you’d have got an NXDOMAIN error.

Do you have an index.html in your builds?

1 Like

I do. As I said, the build for branch ‘r-v1-1’ works at ‘r-v1-1.viewyourtour.com’. It’s adding the second subdomain at ‘still-hopes.r-v1-1.viewyourtour.com’ that triggers the ‘Not Found’ error.

You can have a subdomain of a subdomain, I think the issue here is that as you state above.

uses the first subdomain as the argument for what info to pull from my API.

So if there is a still-hopes.r-v1-1.viewyourtour.com it could be looking for a response from your API for still-hopes.r-v1-1, is there a case for this in your API OR are you trying to route still-hopes.r-v1-1 to actually hit the API still-hopes.viewyourtour ?
This might not make sense since then you’re hitting the same API as prod but that depends what you’re testing? In your last note, you mentioned:

I’ve tried creating a CNAME record for ‘still-hopes.r-v1-1.viewyourtour.com’ that points to ‘r-v1-1.viewyourtour.com’ but I just continue to get a Not Found error.

As your original domain requires the subdomains for the information to be retrieved, I don’t see why you would direct to r-v1-1 since (in my mind) that will be emulating your primary domain “https://viewyourtour.com” and therefore would need a subdomain to send the API request as mentioned above.

Good thoughts.

I’m hitting the same API as prod, but my problem here is the URL of still-hopes.r-v1-1. returns a Not Found error. If just the API was failing, it would still return a (poorly) functioning site.

I’m trying to route still-hopes.r-v1-1. to hit r-v1-1, since r-v1-1 is my dev branch build. If I point straight to viewyourtour.com, no r-v1-1 subdomain, it will just be using the master branch and I can’t test my dev code. For the record, still-hopes.viewyourtour.com works perfectly and is in production use.

1 Like

Hmm yeah, I understand the goal etc, just haven’t had to handle the problem before. Hopefully someone can help! I’ll pop back here if I have any ideas

Hey @The_Vectre,
I don’t think you can accomplish what you’re trying to do with redirects and branch deploys. Branch deploys already require some special DNS magic that won’t play well with internal redirects to the same site.

That said! Because you:

  1. are on at least a Pro plan
  2. are using Netlify DNS

you will be able to get close to what you want with wildcard subdomains, which is something we can enable for sites that meet the above criteria.

Wildcard subdomains (or in this case, wildcard sub-subdomains) would mean that any request that matched *.r-v1-1.viewtourdev.com would go to the same underlying site, and then your client-side logic could do its thing to return the site it’s supposed to based on the sub-subdomain. To get this working, you would need:

  1. a separate site from your production site
  2. with its own custom domain, like r-v1-1.viewtourdev.com
  3. that deploys from the same repo as your prod site, but from the dev branch you want instead of main/master

Note that this configuration would not be using your branch name to determine the domain name… in other words, we cannot do *.*.viewtourdev.com- you will have to pick one subdomain and stick with it. But a wildcard in the sub-subdomain spot will work, which should work with the way your API is set up.

The wildcard subdomain feature may also work well for your production sites.

I see that we have a ticket open with you in our helpdesk, so I’ll follow up with you there, but wanted to post some of this here in case it’s of interest to others :slight_smile:

1 Like

Thanks for posting that here Jen! I was curious how this situation would be handled myself :slight_smile: