question

CaptainNemo-6245 avatar image
0 Votes"
CaptainNemo-6245 asked CaptainNemo-6245 answered

Naked Domain redirects with Azure App Service (Code)

Hi. We use Azure App Service with different web apps. These Linux web apps have configured as publish as "Code" with a "node" runtime stack running on "Linux".

The web app is already using a custom domain which works well (e.g. www.contoso.com). What we want in addition, to redirect the requests on the naked domain https:// to https://www.

How can we do this without using additional network components or add a redirect to the code?

Thanks
Mark

azure-webappsazure-webapps-custom-domains
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Grmacjon-MSFT avatar image
0 Votes"
Grmacjon-MSFT answered

Hi @CaptainNemo-6245

This can be done using App Service Managed Certificate (preview) for your apex domain. You can learn more about this feature here.

You can try this Powershell script:

   #Connect-AzureRmAccount
            
   $subscription = "SUBSCRIPTION-ID"
   $resourceGroupName = "RESOURCE-GROUP-NAME"
   $appServicePlanName = "APP-SERVICE-PLAN-NAME"
   $subjectName = "DOMAIN-NAME"
            
   Set-AzureRmContext -SubscriptionId $subscription
            
   $appServicePlan = Get-AzureRmResource `
       | Where-Object {$_.ResourceGroupName -eq $resourceGroupName } `
       | Where-Object {$_.Name -eq $appServicePlanName}
            
   New-AzureRMResourceGroupDeployment `
       -ResourceGroupName $resourceGroupName `
       -SubjectName $subjectName `
       -AppServicePlanName $appServicePlanName `
       -Location $appServicePlan.Location `
       -TemplateFile "CreateHttpFreeCert.json" 

This script will only create an App Service Managed Certificate for a custom domain that has already been added to your web app. If you run this script before adding a custom domain to the web app, the script will fail.

The -TemplateFile parameter should point to your Azure RM template JSON file. The ARM template specified in this script uses the "CreateHttpFreeCert.json" file.

Hope that helps. Please let us know if you have further questions

Thanks,
Grace

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

CaptainNemo-6245 avatar image
0 Votes"
CaptainNemo-6245 answered

Thank you so much for your feedback - I read this but couldn't understand if this was solving my problem :-)

I already have a custom domain with a wildcard certificate configured. With the script above, an App Service Certificate will be created. 1) I don't get it, why an additional certificate is needed as we have one already.

2) Also I struggle to see how the redirect from https:// to https://www. will be defined.

Do you have some additional pointers/inputs for me?

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.