Hosting a permanent redirect in Azure

WordPress charges for each domain attached to a blog. That is a bit much when you consider .net, .org, .whatever domains that are used on top of the .com domain most use. To get the use out of a single domain, a permanent redirect can be used.  Since Azure has a fixed price, invariant of how many domains you host there; it can be used for the permanent redirect.

Prerequisites

To complete this tutorial:

  • Create an App Service app, or use an app that you created for another tutorial.
  • Purchase a domain name and make sure you have access to the DNS registry for your domain provider (such as GoDaddy).

    For example, to add DNS entries for contoso.com and www.contoso.com, you must be able to configure the DNS settings for the contoso.comroot domain.

    Note

    If you don’t have an existing domain name, consider purchasing a domain using the Azure portal.

Prepare the app

To map a custom DNS name to a web app, the web app’s App Service plan must be a paid tier (SharedBasicStandard, or Premium). In this step, you make sure that the App Service app is in the supported pricing tier.

Note

App Service Free and Shared (preview) hosting plans are base tiers that run on the same Azure VM as other App Service apps. Some apps may belong to other customers. These tiers are intended to be used only for development and testing purposes.

Sign in to Azure

Open the Azure portal and sign in with your Azure account.

From the left menu, select App Services, and then select the name of the app.

Portal navigation to Azure app

You see the management page of the App Service app.

Check the pricing tier

In the left navigation of the app page, scroll to the Settings section and select Scale up (App Service plan).

Scale-up menu

The app’s current tier is highlighted by a blue border. Check to make sure that the app is not in the F1 tier. Custom DNS is not supported in the F1tier.

Check pricing tier

If the App Service plan is not in the F1 tier, close the Scale up page and skip to Map a CNAME record.

Scale up the App Service plan

Select any of the non-free tiers (D1B1B2B3, or any tier in the Production category). For additional options, click See additional options.

Click Apply.

Check pricing tier

When you see the following notification, the scale operation is complete.

Scale operation confirmation

Map your domain

You can use either a CNAME record or an A record to map a custom DNS name to App Service. Follow the respective steps:

Note

You should use CNAME records for all custom DNS names except root domains (for example, contoso.com). For root domains, use A records.

Map a CNAME record

In the tutorial example, you add a CNAME record for the www subdomain (for example, www.contoso.com).

Access DNS records with domain provider

Note

You can use Azure DNS to configure a custom DNS name for your Azure Web Apps. For more information, see Use Azure DNS to provide custom domain settings for an Azure service.

Sign in to the website of your domain provider.

Find the page for managing DNS records. Every domain provider has its own DNS records interface, so consult the provider’s documentation. Look for areas of the site labeled Domain NameDNS, or Name Server Management.

Often, you can find the DNS records page by viewing your account information, and then looking for a link such as My domains. Go to that page and then look for a link that is named something like Zone fileDNS Records, or Advanced configuration.

The following screenshot is an example of a DNS records page:

Example DNS records page

In the example screenshot, you select Add to create a record. Some providers have different links to add different record types. Again, consult the provider’s documentation.

Note

For certain providers, such as GoDaddy, changes to DNS records don’t become effective until you select a separate Save Changes link.

Create the CNAME record

Add a CNAME record to map a subdomain to the app’s default hostname (<app_name>.azurewebsites.net, where <app_name> is the name of your app).

For the www.contoso.com domain example, add a CNAME record that maps the name www to <app_name>.azurewebsites.net.

After you add the CNAME, the DNS records page looks like the following example:

Portal navigation to Azure app

Enable the CNAME record mapping in Azure

In the left navigation of the app page in the Azure portal, select Custom domains.

Custom domain menu

In the Custom domains page of the app, add the fully qualified custom DNS name (www.contoso.com) to the list.

Select the + icon next to Add hostname.

Add host name

Type the fully qualified domain name that you added a CNAME record for, such as www.contoso.com.

Select Validate.

The Add hostname page is shown.

Make sure that Hostname record type is set to CNAME (www.example.com or any subdomain).

Select Add hostname.

Add DNS name to the app

It might take some time for the new hostname to be reflected in the app’s Custom domains page. Try refreshing the browser to update the data.

CNAME record added

If you missed a step or made a typo somewhere earlier, you see a verification error at the bottom of the page.

Verification error

Map an A record

In the tutorial example, you add an A record for the root domain (for example, contoso.com).

Copy the app’s IP address

To map an A record, you need the app’s external IP address. You can find this IP address in the app’s Custom domains page in the Azure portal.

In the left navigation of the app page in the Azure portal, select Custom domains.

Custom domain menu

In the Custom domains page, copy the app’s IP address.

Portal navigation to Azure app

Access DNS records with domain provider

Note

You can use Azure DNS to configure a custom DNS name for your Azure Web Apps. For more information, see Use Azure DNS to provide custom domain settings for an Azure service.

Sign in to the website of your domain provider.

Find the page for managing DNS records. Every domain provider has its own DNS records interface, so consult the provider’s documentation. Look for areas of the site labeled Domain NameDNS, or Name Server Management.

Often, you can find the DNS records page by viewing your account information, and then looking for a link such as My domains. Go to that page and then look for a link that is named something like Zone fileDNS Records, or Advanced configuration.

The following screenshot is an example of a DNS records page:

Example DNS records page

In the example screenshot, you select Add to create a record. Some providers have different links to add different record types. Again, consult the provider’s documentation.

Note

For certain providers, such as GoDaddy, changes to DNS records don’t become effective until you select a separate Save Changes link.

Create the A record

To map an A record to an app, App Service requires two DNS records:

  • An A record to map to the app’s IP address.
  • TXT record to map to the app’s default hostname <app_name>.azurewebsites.net. App Service uses this record only at configuration time, to verify that you own the custom domain. After your custom domain is validated and configured in App Service, you can delete this TXT record.

For the contoso.com domain example, create the A and TXT records according to the following table (@ typically represents the root domain).

Record type Host Value
A @ IP address from Copy the app’s IP address
TXT @ <app_name>.azurewebsites.net

When the records are added, the DNS records page looks like the following example:

DNS records page

Enable the A record mapping in the app

Back in the app’s Custom domains page in the Azure portal, add the fully qualified custom DNS name (for example, contoso.com) to the list.

Select the + icon next to Add hostname.

Add host name

Type the fully qualified domain name that you configured the A record for, such as contoso.com.

Select Validate.

The Add hostname page is shown.

Make sure that Hostname record type is set to A record (example.com).

Select Add hostname.

Add DNS name to the app

It might take some time for the new hostname to be reflected in the app’s Custom domains page. Try refreshing the browser to update the data.

A record added

If you missed a step or made a typo somewhere earlier, you see a verification error at the bottom of the page.

Verification error

Map a wildcard domain

In the tutorial example, you map a wildcard DNS name (for example, *.contoso.com) to the App Service app by adding a CNAME record.

Access DNS records with domain provider

Note

You can use Azure DNS to configure a custom DNS name for your Azure Web Apps. For more information, see Use Azure DNS to provide custom domain settings for an Azure service.

Sign in to the website of your domain provider.

Find the page for managing DNS records. Every domain provider has its own DNS records interface, so consult the provider’s documentation. Look for areas of the site labeled Domain NameDNS, or Name Server Management.

Often, you can find the DNS records page by viewing your account information, and then looking for a link such as My domains. Go to that page and then look for a link that is named something like Zone fileDNS Records, or Advanced configuration.

The following screenshot is an example of a DNS records page:

Example DNS records page

In the example screenshot, you select Add to create a record. Some providers have different links to add different record types. Again, consult the provider’s documentation.

Note

For certain providers, such as GoDaddy, changes to DNS records don’t become effective until you select a separate Save Changes link.

Create the CNAME record

Add a CNAME record to map a wildcard name to the app’s default hostname (<app_name>.azurewebsites.net).

For the *.contoso.com domain example, the CNAME record will map the name * to <app_name>.azurewebsites.net.

When the CNAME is added, the DNS records page looks like the following example:

Portal navigation to Azure app

Enable the CNAME record mapping in the app

You can now add any subdomain that matches the wildcard name to the app (for example, sub1.contoso.com and sub2.contoso.com match *.contoso.com).

In the left navigation of the app page in the Azure portal, select Custom domains.

Custom domain menu

Select the + icon next to Add hostname.

Add host name

Type a fully qualified domain name that matches the wildcard domain (for example, sub1.contoso.com), and then select Validate.

The Add hostname button is activated.

Make sure that Hostname record type is set to CNAME record (www.example.com or any subdomain).

Select Add hostname.

Add DNS name to the app

It might take some time for the new hostname to be reflected in the app’s Custom domains page. Try refreshing the browser to update the data.

Select the + icon again to add another hostname that matches the wildcard domain. For example, add sub2.contoso.com.

CNAME record added

Edit the web.config using Kudu Console

There are two ways to access Kudu:

  1. Simply modify your website URL and by adding scm to it. If you site is http://mysite.azurewebsites.net/, then the root URL of the Kudu service is https://mysite.scm.azurewebsites.net/. Note the added scm token.
  2. Using the Azure Portal. First Navigate to your Web App, Select Tools -> Kudu -> Go:

launch Kudu from azure portal

How to View, Add, Edit, and Remove files in Azure Web App using Kudu

Finally this post was about how you actually view, edit, add, and remove files from the Web App. Once you have your Kudu service Dashboard open you will see some basic information and links for more complex tasks:

Kudu home page

View Current Files

View current files in your application by Clicking on Debug Console -> CMD:

Kudu view files

Once you are viewing the folder structure you can get to your application home directory by clicking the site folder:

Kudu site folder

 

Edit Files

To edit a file click the pencil icon:

launch Kudu from azure portal

Locate the web.config (or create it) and change the text to the following:


<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect old-domain to new-domain" stopProcessing="true">
<match url=".*" />
<action type="Redirect" url="http://<<appdomain>>/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

view raw

web.config

hosted with ❤ by GitHub

Replace <<appdomain>> with the domain you wish to redirect to.

 

2 thoughts on “Hosting a permanent redirect in Azure

  1. After wading through all that i’m none the wiser. I configured niequestions.com in azure and want to have the other domain i purchased niequestions.co.uk redirect to the .com one – none of the above seems relevant – I could create a web app for the .co.uk domain and do a redirect html page – but i was hoping that i could somehow just add a cname dns record for the .co.uk in the .com dns config – any advice? thanks.

Leave a Reply to John BlairCancel reply