Avoiding HTTP double redirects with WP Engine

With HTTPS becoming a standard, redirecting your old http url typically works by selecting a checkbox. With WP Engine, select “Secure all URLs” within the SSL settings. Recently I discovered that a lot of these http urls were double redirecting. To explain let’s take a look at my personal site austinginder.com.

Using CURL reveals the double redirect

CURL is an amazing tool. The flags -sLI tells CURL to silently output the headers and follow the redirects. With grep we can filter out the header info to see only relevant redirection info. This reveals that http://www.austinginder.com redirects to http://austinginder.com and then to https://austinginder.com. Before I get into the solution here is how my setup was configured within WP Engine’s portal.

SSL applied on both www and nonwww versions.
All domains configured to redirect to nonwww version.

In order to remove the extra hop I first turned off WP Engine’s domain redirect and then enabled a custom redirection rule for the www.austinginder.com domain. That will looks like the following.

This redirection rule acts as a catch all forward. Anything sent to www.austinginder will be redirected to https://austinginder.com. To confirm we can run the CURL command again.

curl -sLI http://www.austinginder.com | grep "HTTP\|Location"

This time it should only output the single redirect.

HTTP/1.1 301 Moved Permanently
Location: https://austinginder.com/
HTTP/2 200

You can expand this to test other pages to ensure the redirects are going to the correct location.

curl -sLI http://www.austinginder.com/wp-login.php | grep "HTTP\|Location"
HTTP/1.1 301 Moved Permanently
Location: https://austinginder.com/wp-login.php
HTTP/2 200