Support Forums

Wildcard subdomains and staging environments for our multi-tenancy site


We’re considering moving the hosting of our multi-tenancy site from Vercel to Netlify. The site will allow users to decide their own subdomains, so we need the following requirements:

  1. It’s possible to use wildcards for subdomains such as *.our-custom-domain.com
  2. It’s possible to create multiple staging environments such as *.staging-1.com *.staging-2.com without subdomain reserved by the system

As for #1, we could configure DNS, but routing on the Netlify side has been failed. Referring to a past topic, it could be enabled for Pro plans and above, so we’d like to have it enabled.

As for #2, the system automatically assigns subdomains for both Deploy Preview and Branch Deploy, so the subdomain entered by the user must be treated as a sub-subdomain for testing, which makes a difference from the production environment. In Vercel, the same problem has occurred, and we had to create projects for each staging environment and set the same environment variables, which was a complicated operation. Is there any way to achieve this on Netlify, even if the configuration is more complicated?

Thank you!
~ Yohsuke

Hi @ino256,

Wildcard domains can be enabled but I’d advise you to read the following first:

  • Either you have to use Netlify DNS so we can get you a wildcard SSL cert, or you must bring a custom wildcard certificate.
  • We can only do this for a site that’s on a paid team.
    Also note:

You can’t use domain aliases on the site with Wildcard subdomains enabled, just the bare domain and subdomains under your primary domain. If you try to add a domain alias then it won’t work.
The primary custom domain for the site, if it is a example.com with www.example.com setting in our UI, must be www.example.com and not example.com!

Once the wildcard subdomain feature is enabled, you do not need to add new subdomains under the site settings. You’ll will need still need to create DNS records.

This might be a single wildcard DNS record for all subdomains (like a CNAME for *.example.com pointing to the netlify.app subdomain for the site). Alternatively, you can also create the individual DNS records to add each subdomain (like CNAMEs for subdomain-a.example.com, subdomain-b.example.com, etc.) as covered in our external DNS documentation. Both work so please do whichever you prefer.

About the second point, I’m not 100% sure what the requirement is. It appears that you wish to assign custom domains to staging environments? Well, you can apply subdomains to branch deploys but not to deploy previews. So, you’d have to create a different project for each of the staging environment, much like you did on Vercel.

Hi @hrishikesh ,
Thank you for your reply.

I understand the restriction on the wildcard subdomain. What do we do next to enable?

As for #2, for example, Slack has a very similar structure: Slack allows users to create workspaces with a name they decide, and each workspace is assigned a different subdomain, such as xxxxxx.slack.com. If we want to actually develop this, we need to get the ID of the workspace from the subdomain even in the staging environment. For example, in the case of Deploy Preview, a URL like deploy-preview-my-project.netlify.com is treated as the URL of the site, and a workspace URL is like xxxxxx.deploy-preview-my-project.netlify.com. It needs to be modified only for the staging environment to get the workspace ID from the sub-subdomain.
What we are looking for is the ability to build a staging environment that allows full control over the domains, not sub-domains. We want to deploy the main branch to https://example.com and the staging-1 branch to https://staging-1-example.com , without having to create multiple projects.

Thank you.

Nothing much. Just let us know which site it is for, and we’d get it done.

Unfortunately, if you need a different branch on a totally different apex domain, you’d have to create it as a separate website.