Fix endless redirection with https setting at Wordpress and using AWS load balancer

April 10, 2020

Problem: I set up a WordPress blog at 2 Amazon Web Service (AWS) EC2 instances at different availability zone. In front of them, a elastic load balancer (ELB) is set up, which redirect all HTTP port 80 requests to HTTPS port 443. Since the wp-config.php was not updated, the requests are still using HTTP instead. Therefore, I updated the below values to https:

    define('WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST'] . '/');
    define('WP_HOME', 'https://' . $_SERVER['HTTP_HOST'] . '/');

However, it falls into a redirection loop, and hit too many redirections.

Solution: Add this line in the wp-config.php

    $_SERVER['HTTPS'] = 'on';

And it would fix the issue. This kind of configuration is hard to troubleshoot and you may be stuck with many hours to find this simple solution. Hope you can search this post if you encounter this particular issue.

Profile picture

Experience in software development, application architecture, and deploying cloud solutions for enterprise customers. Strong hands-on skills with a Master's degree in Computer Science and business acumen with a master of business administration (MBA) in Finance. Certified in Amazon Web Services (AWS), Google Cloud Platform (GCP), Microsoft Azure, Kubernetes (CKA, CKAD, CKS, KCNA) and Scrum (PSM, PSPO) with experience in building banking products from scratch. Connect on Linkedin

© 2022, @victorleungtw