Handling Apex(root) Domains for Azure Front Door

By alan.wallace, 9 October, 2023

Azure Front Door is a great product, but one limitation that exists is the inability to handle apex domains that are not handled through Azure DNS.  This leaves two options: 

  1. Move your DNS to Azure
  2. Host your site on a subdomain, such as www

If you choose option 2, I'm sure you will still want your apex domain to redirect to the subdomain, however.  Azure Web Apps do not have the same limitation.  You can create a small application which runs in an Azure Web App that performs this redirection.  Fortunately, this is an incredibly simple application to write with .NET Core.

using Microsoft.AspNetCore.Rewrite;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
var options = new RewriteOptions()
                  .AddRedirect("(.*)", "https://www.yourdomain.com/$1", 301);

That's it, that's the entire source code for your web app.  Simply deploy to your Azure Web App, point your apex domain at it and you're ready to go!