How to set up Azure Static Website redirect from naked domain to www

899 views Asked by At

I have Azure static website mapped to a custom domain hosted with GoDaddy. I am using Azure CDN for https as per Microsoft instructions.

This is all working fine if I type www.example.com. But if I omit www subdomain, I get NET::ERR_CERT_COMMON_NAME_INVALID error.

How can I redirect from naked domain to www?

I tried using Azure CDN "rule engine" to add a permanent redirect but it does not seem to work. I also tried adding forwarding from naked to www subdomain in GoDaddy DNS config, but that does not work either. Still getting errors.

Someone has suggested to create a certificate that covers both naked and www subdomains, but not sure if that is possible in Azure CDN.

Does anyone know how this can be accomplished in Azure?

1

There are 1 answers

4
Kartik Bhiwapurkar On

• The error message that you are encountering while browsing the naked domain, for e.g.: - ‘example.com’ is ‘ NET::ERR_CERT_COMMON_NAME_INVALID ’ which clearly resembles that there is no existing ‘A’ record found for the naked domain DNS record, i.e., ‘example.com’ in this case. While there may exist an ‘A’ record for ‘www.example.com’, ‘mail.example.com’ or ‘app.example.com’ due to which when you are trying to browse these, they are readily accessible, but the same is not possible for your naked custom domain.

Thus, to resolve this issue, you will have to create an ‘A’ record in your public DNS registrar, i.e., GoDaddy for your naked domain, i.e., ‘example.com’ or for a wildcard entry ‘*.example.com’ so that when you are trying to directly access your custom domain name, you will be redirected to the original Azure static website.

https://support.microsoft.com/en-us/topic/associating-a-custom-domain-name-and-securing-communication-with-azure-0eeba4ff-3432-e59a-7f7a-0ee8c7cd7c11

• But, for the same thing above to be accessible over HTTPS, you will have to upload an SSL/TLS certificate in Azure keyvault and integrate it with Azure CDN as described in the Microsoft documentation below. Also, you need to ensure that common names like ‘*.example.com’, ‘example.com’ and others needed are already included in that certificate. To be more precise, a wildcard certificate if requested and generated will work best in these scenarios and be of use in all circumstances.

https://learn.microsoft.com/en-us/azure/cdn/cdn-custom-ssl?tabs=option-2-enable-https-with-your-own-certificate#tlsssl-certificates