Search code examples
azureazure-web-app-servicesubdomainurl-routingcustom-domain

How to define exceptions for a wildcarded Azure app service subdomain


I have an Azure app service which has a custom domain configuration with *.example.com cname. I want to add another app service for admin.example.com subdomain. But all other subdomains should go to the first app. How should I proceed to achieve this? Should I define a new app service as a router which uses *.example.com? Are there any better solutions on Azure?


Solution

  • You don't need a new app service as a router. In fact, all other subdomains will go to the first app service, only the specific subdomain admin.example.com will go to the second app service if there is hostname admin.example.com according to your current configuration.

    In this case, you have two CNAME records in your DNS domain provider. One is for *.example.com subdomain, another is for admin.example.com subdomain. A wildcard DNS record is a record that will match requests for non-existent subdomains. You can add a wildcard hostname *.example.com in the custom domain of the first app service, then it will match all subdomain for that domain example.com. When you add it, make sure you have the following records in your domain provider. Refer to this answer.

    • CNAME * entry that points to yourapp.azurewebsites.net
    • CNAME awverify entry that points to awverify.yourapp.azurewebsites.net

    When you have a DNS query. The DNS name admin.example.com will be resolved rather than all other subdomain hostnames because if a separate subdomain is created, it has a higher priority than wildcard. Refer to this.

    At last, you can have a DNS lookup tool to verify the DNS query result.