Since I had to go through this process a few times lately, and it is not as straightforward as one could hope, I think the world needs this post 🙂
Create the DNS records
Add custom domain to Azure Web App
At this point if you try to access your domain you will get the following error: “Error 404 – Web app not found … The web app owner has registered a custom domain to point to the Microsoft Azure App Service, but has not yet configured Azure to recognize it”
To fix this error, you will need to add your custom domain as a hostname in Azure portal.
Browse to your Web App => All settings => Custom domains and SSL => HOSTNAMES ASSIGNED TO SITE, and add both the root and the www subdomain.
You may need to allow for some time after you have configured your DNS records. The official time frame for propagating domains is up to 24 hours, but in my experience if the DNS is set correctly it won’t take longer than 20 minutes.
Now if you browse to your domain you will see your WordPress site, yay!
However, you aren’t done yet.
If you click on one of the links on the site you will notice that WordPress still redirects you to the initial domain on someone.azurewebsites.net. To fix that you need to update the domain set in WordPress itself.
DO NOT update it through WordPress Dashboard => Settings => General. This does not work (at least currently) and might lock you out of the application! 😯
Instead you will need to FTP into your site and change the functions.php of your currently active theme.
FTP into the site using FileZilla
Open the publish settings file you have downloaded, and look for FTP.
Copy the publishUrl, userName and userPWD into FileZilla and click Quickconnect. (The publishUrl is the Host).
* I chose FileZilla for the demonstration since it is free and easy to use. You can certainly use other applications to FTP into the site.
Update siteurl in functions.php
Browse to your /site/wwwroot/wp-content/themes/THEME_NAME, where THEME_NAME is the name of your active theme.
Find the file functions.php and copy it over to your local machine (or simply right-click and choose View/Edit to edit the file on the fly).
Add the following two lines right after the opening
Upload the file back into the site using FileZilla.
* Note that your active theme might not have a functions.php file. In this case you can add one yourself. Please read this post for further details https://codex.wordpress.org/Changing_The_Site_URL
Your site will be down for a couple of minutes, so wait for it to come back up and sign in. Now you can browse to WordPress Dashboard => Settings => General and see if the URL settings got updated:
Now that your site is back up and running, you should remove the lines you added from functions.php. The WordPress manual claims it is important to clean them up 😉
OK, we are good to go! Anyone who browses to your site will now be redirected to the siteurl you just set up as a root URL, regardless of how they got to the site in the first place. Happy browsing!