Support Forums

How to use subdomain for preview deploys


I’m running a react app with conditional module rendering based on subdomains. Its an eCommerce solution with a customer facing app, admin/backend and a root for our static landing pages.
In order to render the different modules we have a simple window.location.host.split(".")[0] to get the different subdomains ( or root). This works when its published to our domain but raises issues with the random domains provided for the preview apps.
When accessing a subdomain on the preview app Chrome replies with a “connection is not private” error:
"…When Google Chrome tried to connect to admin.my-random-preview.netlify.app this time, the website sent back unusual and incorrect credentials… "

Is there a way to make this work with the “preview app” function, or do I have to setup another domain in order to get a staging site working with subdomains?

Hi @fowl,

Instead of using the random URLs, you could get specific URLs for the branch from the UI. For example, a branch named staging would be called staging--website.netlify.app. However, you’d face the certificate issue on that too.

But there’s way to fix that. You could assign a custom subdomain to the branch and if you can get a certificate for the *.*.custom-domain.com you’d be good to go. If a custom certificate is not possible, I’m afraid you’d have to try this on an apex domain only.

Could you elaborate on how to get a certificate for the *.*.domain.com? I’m using Netlifys nameservers and hosting the domain on GoDaddy.

Or if its possible to setup a staging.*.my-domain.com - not sure if *.*.my-domain.com is possible to archive.

Hi @fowl,

When I said, get a custom certificate, I meant you’d have to get it from an external provider. Netlify can’t configure *.*.domain.com for the same website. However, you could add subdomain.domain.com as a primary domain to a website and then deploy a branch deploy to get branch.subdomain.domain.com.