I’ve been experimenting with setting up Traefik as my main reverse proxy server for my home infrastructure. As part of that test, I wanted to put WordPress behind Traefik while serving the site up in SSL. After a long day of setting up Traefik and WordPress using Ansible, I kept getting too many redirects for WordPress behind Traefik when SSL is enabled.

After doing much research (and with the help of a really good friend, Jero), I was able to resolve it. Turned out that the fix was quite simple. Here’s an article that explains what’s going on with the fix. But the summary of the fix is to add the following lines to the end of the wp-config.php file

/**
 * Handle SSL reverse proxy
 */
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
    $_SERVER['HTTPS']='on';

if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
    $_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST'];
}

Too many redirects for WordPress behind Traefik when SSL is enabled