|
| 1 | +--- |
| 2 | +title: Set up an apex domain in Azure Static Web Apps |
| 3 | +description: Configure the root domain in Azure Static Web Apps |
| 4 | +services: static-web-apps |
| 5 | +author: craigshoemaker |
| 6 | +ms.service: static-web-apps |
| 7 | +ms.topic: how-to |
| 8 | +ms.date: 02/11/2022 |
| 9 | +ms.author: cshoe |
| 10 | +--- |
| 11 | + |
| 12 | +# Set up an apex domain in Azure Static Web Apps |
| 13 | + |
| 14 | +Domain names without a subdomain are known as apex or root domains. For example, the domain `www.example.com` is the `www` subdomain joined with the `example.com` apex domain. |
| 15 | + |
| 16 | +Some domain registrars (like Google and GoDaddy) don't allow you to point the apex domain to an existing URL. If your registrar doesn't support `ALIAS` or `ANAME` records, or doesn't allow `CNAME` flattening, then you can't point your apex domain to the generated URL for your static web app. |
| 17 | + |
| 18 | +If your registrar doesn't allow you to redirect the apex domain, consider the following options: |
| 19 | + |
| 20 | +* Configure your domain with [Azure DNS](custom-domain.md) |
| 21 | +* Forward the apex domain to the `www` subdomain |
| 22 | + |
| 23 | +This guide demonstrates two options for configuring an apex domain. |
| 24 | + |
| 25 | +* Use the steps to [set up with an ALIAS record](#set-up-with-an-alias-record) if your domain registrar supports the `ALIAS` DNS record. |
| 26 | + |
| 27 | + If your registrar doesn't support `ALIAS` records, but does support `ANAME` records or `CNAME` flattening, see their documentation for configuration settings. |
| 28 | + |
| 29 | +* Use the steps in [forward to www subdomain](#forward-to-www-subdomain) if your domain registrar doesn't support the `ALIAS` DNS record. |
| 30 | + |
| 31 | +## Set up with an ALIAS record |
| 32 | + |
| 33 | +Before you create the `ALIAS` record, you first need to validate that you own the domain. |
| 34 | + |
| 35 | +### Validate ownership |
| 36 | + |
| 37 | +1. Open the [Azure portal](https://portal.azure.com). |
| 38 | + |
| 39 | +1. Navigate to your static web app. |
| 40 | + |
| 41 | +1. From the *Overview* window, copy the generated **URL** of your site and set it aside in a text editor for future use. |
| 42 | + |
| 43 | +1. Under *Settings*, select **Custom domains**. |
| 44 | + |
| 45 | +1. Select the **+ Add** button. |
| 46 | + |
| 47 | +1. In the *Enter domain* tab, enter your apex domain name. |
| 48 | + |
| 49 | + For instance, if your domain name is `example.com`, enter `example.com` into this box (without any subdomains). |
| 50 | + |
| 51 | +1. Select the **Next** button. |
| 52 | + |
| 53 | +1. In the *Validate + Configure* tab, enter the following values. |
| 54 | + |
| 55 | + | Setting | Value | |
| 56 | + |---|---| |
| 57 | + | Domain name | This value should match the domain name you entered in the previous step. | |
| 58 | + | Hostname record type | Select **TXT**. | |
| 59 | + |
| 60 | +1. Select the **Generate code** button. |
| 61 | + |
| 62 | + Wait as the code is generated. It make take a minute or so to complete. |
| 63 | + |
| 64 | +1. Once the `TXT` record value is generated, select the **copy button** (next to the generated value) to copy the code to the clipboard. |
| 65 | + |
| 66 | +1. Select the **Close** button. |
| 67 | + |
| 68 | +1. Open a new browser tab and sign in to your domain registrar account. |
| 69 | + |
| 70 | +1. Navigate to your domain name's DNS configuration settings. |
| 71 | + |
| 72 | +1. Add a new `TXT` record with the following values. |
| 73 | + |
| 74 | + | Setting | Value | |
| 75 | + |--|--| |
| 76 | + | Type | `TXT` | |
| 77 | + | Host | Enter **@** | |
| 78 | + | Value | Paste the generated code value you copied from the Azure portal. | |
| 79 | + | TTL (if applicable) | Leave as default value. | |
| 80 | + |
| 81 | +1. Save changes to your DNS record. |
| 82 | + |
| 83 | +### Set up an ALIAS record |
| 84 | + |
| 85 | +1. Return to your domain name's DNS configuration settings. |
| 86 | + |
| 87 | +1. Add a new `ALIAS` record with the following values. |
| 88 | + |
| 89 | + | Setting | Value | |
| 90 | + |--|--| |
| 91 | + | Type | `ALIAS` | |
| 92 | + | Host | Enter **@** | |
| 93 | + | Value | Paste the generated code value you copied from the Azure portal. Make sure to remove the `https://` prefix from your URL. | |
| 94 | + | TTL (if applicable) | Leave as default value. | |
| 95 | + |
| 96 | +1. Save changes to your DNS record. |
| 97 | + |
| 98 | + Since DNS settings need to propagate, this process can take some time to complete. |
| 99 | + |
| 100 | +1. Open a new browser tab and navigate to your apex domain. |
| 101 | + |
| 102 | + After the DNS records are updated, you should see your static web app in the browser. Also, inspect the location to verify that your site is served securely using `https`. |
| 103 | + |
| 104 | +## Forward to www subdomain |
| 105 | + |
| 106 | +Each domain registrar has a different process for managing domain names. Once you sign in to your account with your registrar, look for domain forwarding options. Some registrars have this functionality listed under *DNS options*, while others have them associated with *Website options*. |
| 107 | + |
| 108 | +Make sure as you set up forwarding that you only configure the apex domain to forward to the `www` subdomain. |
| 109 | + |
| 110 | +See your registrar's documentation for details. |
| 111 | + |
| 112 | +## Next steps |
| 113 | + |
| 114 | +> [!div class="nextstepaction"] |
| 115 | +> [Manage the default domain](custom-domain-default.md) |
0 commit comments