Home
Support Forums

Deep subdomains like staging.app.domain.com

Hi,

I have a custom domain that looks something like this : domain.com
I want to have a development environment which will be staging.
I’ve created a staging deploys branch in Netlify UI and one on git aswell, it works well : when I push to staging branch, it deploys to staging.domain.com subdomain.

But now I want to add another subdomain which is feature related : admin subdomain.

Is this possible to combine both subdomain and have a result that will look like staging.admin.domain.com? Or is it a bad practice? What would be the recommanded way otherwise?

Thanks!

Hi @GreatHawkeye,

I won’t say it’s a bad practice, but I don’t think the SSL certificate would be able to configure *.*.domain.com. It’s better to create a different website for the admin branch and add the staging subdomain to it.

1 Like

When you say “create a different website”, do you mean clicking “New site from Git” again and link it to the same repo? But this time adding “admin” branch as the production branch maybe?

What would the URL would look like then?

Or maybe you meant a totally different domain name like admin-domain.com?

Yes, that’s what I meant. You could basically add a custom domain to that website and that custom domain would be admin.custom-domain.com. You can also get a branch domain for that website and that would be staging.admin.custom-domain.com. It will then get the correct SSL certificate.

1 Like

Okay so it’s working, when i push to admin branch, it’s deploying to admin.domain.com !
I also added a “staging” branch to the deploys branch of “admin” website, so now when I push to “staging” branch, it deploys correctly to staging.admin.domain.com

But now if I want to also have a staging env for all my websites, I will have to create as many env scoped branches as needed, correct?

For example:

  • For the “main” website (domain.com), the main branch deploys to domain.com, I will have to create a staging-main deploy branch to deploy to staging.domain.com
  • For the “admin” website (admin.domain.com), the admin branch deploys to admin.domain.com, I will have to create a staging-admin deploy branch to deploy to staging.admin.domain.com

Is that correct?

Also, how can I use feature branch in netlify? What if I want to use staging-admin/my-feature?

Hi @GreatHawkeye,

Sorry to be slow to get back here.

Well, branch subdomains need the branch name to be exactly the same as subdomain. So, to get staging.domain.com, the branch has to be called staging. If you name it staging-main, the subdomain should also be staging-main.domain.com. The workaround this limitation would be to create a different website to point to each branch and assign any custom domain you want to that website.

Again, if you publish admin branch as the primary branch of a website, the next branch should be named staging so you could get staging.admin.domain.com.

You could use such a branch but / would be converted to -, and so, the domain would be staging-admin-my-feature. Do note, -- is not allowed as we use it as an separator ourselves. So, you can’t have something like staging-admin-/my-featue as that would convert to staging-admin--my-feature.

1 Like

Thank you very much for these answers!
So I guess the proper workflow for a development team working on the staging env would be to :

  • create a new local branch from staging branch, called for example staging/my-feature
  • after development is complete, create a merge request on github to merge staging/my-feature into staging
  • once this merge request is accepted, it merges this staging/my-feature into staging branch, which triggers the deploy to staging.domain.com

I guess this is an usual workflow?

Hi @GreatHawkeye,

I can’t comment if that’s the usual workflow, as I’ve personally never had to do this.

But yeah, looks like in your case you’d have to do something like that to get around your case.

1 Like