WordPress & Azure Front Door Too Many Redirects

I recently started hosting some WordPress sites on Azure as App Service sites. I wanted to put them behind an Azure Front Door to create a fast and secure experience. However, after setting up the Front Door the WordPress site got stuck in a redirect loop, eventually timing out with the error

ERR_TOO_MANY_REDIRECTS – <domain> redirected you too many times

Firefox would show this as “The page isn’t redirecting properly”

Cause

I had misconfigured the URLs on the Front Door and on the App Service site. When you host a WordPress site behind a Front Door there are a few URLs at play. A misconfiguration can easily cause a redirection loop. If WordPress detects traffic coming into a URL that is different to what is set under Settings => General, it will redirect to it.

I was not setting the host header on the Front Doors back-end pool, and I had not added the front end domain as a custom domain on the App Service site.

In addition, there is a known tweak that needs to be made to WordPress when hosted on Azure using a Linux based App Service site (more on that below).

Resolution

In this section I will cover how things should be configured.

For this example;

  • The domain I want people to enter is www.geekshangout.com this is my front-end domain name.
  • The URL assigned by Microsoft for my App Service site is geekshangout.azurewebsites.net this is whereby back end pool will point.

How it should look

A normal flow should look like this.

WordPress Azure Front Door

Front Door Setup

  • Your Front Door should have the domain you want visitors to use as a front-end domain.
  • For each of the backends in you back-end pool the “Backend host header” should be setup as your front-end domain name not your app service domain name. For example.

App Service Site Setup

Your App Service site will need a custom domain for your front-end domain name, www.geekshangout.com in my example. However, you will hit an issue when you try and add the custom domain. Azure will want you point the domain to the App Service Site to validate it, however this would break you Front Door setup.

Instead, you can add a CNAME for the domain

Name: awverify.www

Alias: App Service domain name

Note: if you front end domain is using a CNAME other than www put that after awverify. instead of www

You will now be able to add the front-end domain as a custom domain on the App Service site without affecting the DNS routing to your Front Door.

WordPress Setup

Under Setting => General the WordPress URL and Site URL should be set as your front-end domain name.

I also had to modify my wp-config.php file to add the following block of code to the top

 // Fix HTTPS Redirect
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false)
   $_SERVER['HTTPS']='on';
else
   $_SERVER['HTTPS']='off';

WordPress Emails and Azure

If you will need to send emails from your WordPress site when hosted on Azure, look at this post WordPress Emails on Azure Configuring SendGrid

Want a fast WordPress theme or looking to improve your Ad revenue?

That a look at my Tools I Use page for some recommendations

Leave a Comment

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