Mapping a wildcard domain name to an Azure App Services Web App (Website)
This article has been moved to its new location here: https://benperk.github.io/waws/2015/2015-12-mapping-a-wildcard-domain-name-to-an-azure-app-services-web-app-website.html
The process for mapping a wildcard domain, for example *.contoso.com to a Web App can be achieved by performing the following:
- Adding a CNAME at your domain hosting provider
- Adding the custom domain within the Azure portal
- Adding wildcard domain names to multiple Web Apps
Once these steps are complete, accessing your Web App using any subdomain name will be enabled. For example, app.contoso.com, email.contoso.com, archive.contoso.com, etc…
Adding a CNAME at your domain hosting provider
Figure 1, adding a wildcard domain to an Azure Web App
Select the FINISH button and save the changes to DNS zone file.
Figure 2, wildcard HOST for CNAME mapping
It is possible that the replication of the DNS record can take up to 48 hours, but in most of my experiences, it happens with minutes, if not immediately…experiences may vary.
Adding the custom domain within the Azure portal
Figure 3, map wildcard domain to Azure Web App
Click on the manage domain button and add any subdomain to the Azure Web App, as shown in Figure 4, and click the check button and then Save th configuration.
Figure 4, adding the subdomains to a wildcard domain map
Now, when I access any of those subdomains, they all route to the same Azure App Service Web App.
Adding wildcard domains to multiple Web Apps
But what happens if I want yes.benjamin.cool to point to a different Web App than cool.benjamin.cool maps to? As expected, when I try to add the subdomain to another Web App, I get an error, as shown in Figure 5.
Figure 5, adding a wildcard domain to multiple Web Apps
I had the idea then to go back to my DNS provider console and add another wildcard CNAME to this second Web App. Similiar to that shown in Figure 1, but this time I wanted it to point to iislogs.azurewebsites.net instead of standard.azurewebsites.net. And that did NOT work. You can have only 1 HOST that equals to *. So, to get yes.benjamin.cool to map to iislogs.azurewebsites.net I added a CNAME for that, as shown in Figure 6.
Figure 6, adding a wildcard subdomain to a second Web App
Not being a DNS expert, I expect the code path for finding the IP to route a request to looks first to see if there is a matching HOST name and routes it to the Points To value if found and if no match is found then it maps to the wildcard domain Points To value.