Wildcard subdomains & redirects

I’ve got a site I’d like to move to netlify that does multi-tenancy based on the subdomain. Because of that, I’d like to know:

  1. Is it possible to set up *.my-site.com as the custom domain for a site?

  2. Is it possible to set up a redirect rule like the following that will preserve the original subdomain:

/api/*    https://*.my-site-api.com/api/*     200

Thanks!
~ Dallin

Hi Dallin!

Number one is possible; it is a feature available for sites on the Pro plan (see Netlify Pricing and Plans), and our Support team must explicitly enable it on your site. There are some conditions, but that is the starting point. I’ll be happy to go into details if the price point and my next answer aren’t a deal breaker.

Number two is only possible when rewriting to the same hostname that we host. For instance:

yourclient.yourcompanysitehostedonnetlify.com/api/* could rewrite to yourclient.yourcompanysitehostedonnetlify.com/otherpath/*…but not to yourclient.asitehostedelsewhere.com/anything . The hostname is not available as a “parameter” in the redirect in any way.

Hi @fool !

I’d like to turn on this exact feature for one of my sites, but have a couple requirements and am wondering if it’s possible:

  1. Host a Netlify site at app.mydomain.com
  2. Host a multi-tenant Netlify (w/ NextJS) site (for customers) on all other subdomains (within the same domain) e.g. *.mydomain.com
  3. and redirect a list of sub-domains to their existing sites (this is because I currently have many customers occupying explicit sub-domains)

Would all 3 requirements work within Netlify (Pro)?

Thanks in advance for your help!

I’m not sure if I understood this point. Could you please elaborate?

1 Like

@hrishikesh

and redirect a list of sub-domains to their existing sites (this is because I currently have many customers occupying explicit sub-domains)

Never mind about all that. :slight_smile:

So really, here’s our one true requirement:

  • Host a multi-tenant Netlify (w/ NextJS) site (for customers) on all subdomains of a domain e.g. *.mydomain.com points to a netlify site (which dynamically renders data, depending on the sub-domain.

We have most if not all DNS and things configured already:

  • We’re on the pro plan
  • The domain we want a subdomain wildcard for is already managed by Netlify DNS :+1: (enabled ipv6 too)
  • We added a CNAME record with * and the value as the netlify app domain :+1:
  • The primary domain for the site is set to myfuturestay.com with the www site redirecting.

But the wildcard isn’t working as expected. When visiting any subdomain we get a blank page responding with Not Found - Request ID: 01GGGGB3NXDVWTGVHJTPW4KBA4.

So:

  1. Does the primary domain need to be the www domain?
  2. Do you need to turn the feature on for our site? If so, can you please do so for: myfuturestay.com
  3. Or what else do we need to configure to get this working?
1 Like

www or any domain as the same level of the required subdomain. For example, www would do if you want *.example.com, but if you want *.foo.example.com, the primary domain should be www.foo.example.com. You can replace www with anything.

Done.

3 Likes

Thank you @hrishikesh . Works perfectly

Last thing I did to get this working was set the www domain as the primary domain for the site

For the record, to maybe help someone else… here are the basic steps I took to get this working:

  1. Ensure our account is on the Pro plan
  2. Add our custom domain to Netlify Managed DNS (e.g. add domain to netlify, point to netlify nameserver, etc.)
  3. Make www domain the primary domain for the Netlify Site
  4. Add the wildcard CNAME record (e.g. name: * value: <site-name>.netlify.app)
  5. Ask Netlify support to turn the feature on for our netlify site
2 Likes

Thanks for coming back and sharing! Happy building :rocket:

1 Like

Hi, can you turn this on for me too?

My site is:

brokerbacon.netlify.app