Fixing HTTPS issues for WordPress hosted on Azure Linux App Services

Shortly after deploying my WordPress site I realized I was having a few issues with HTTPS. I thought it would be as simple as changing the site URL in WordPress and turning on force HTTP in Azure. It was not that simple…

Thankfully there’s not too much you need to do, it took me a few hours to figure it all out, but hopefully this will save you the time I wasted.

Step 1: Enable HTTPS on the Azure App Service

Open your App Service in the Azure portal and enable HTTPS only.

Step 2: Update/Create .htaccess file

Create a .htaccess file in the root directory of your website with the following within it

RewriteCond %{HTTP:X-ARR-SSL} ^$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Step 3: Update wp-config.php

In your wp-config.php file add the following before the MySQL settings

define('FORCE_SSL_ADMIN', true); 
if ( isset($_SERVER['HTTP_X_ARR_SSL']) ) 
        $_SERVER['HTTPS']='on';

Step 4: Update site URLs with HTTPS in WordPress admin

Navigate to your admin portal in WordPress. Click Settings -> General in the sidebar and change your WordPress Address and Site URL with https:// in place of http://

Conclusion

You should be all set with HTTPS after following these steps. If the website is failing to load after changing the URLs in step 4 then you can revert them by changing the database settings or by updating your wp-config, see this document for more information: https://wordpress.org/support/article/changing-the-site-url/#changing-the-site-url

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.