Fixing Endless Redirection with HTTPS Settings in WordPress When Using AWS Load Balancer

April 10, 2020


I set up a WordPress blog on two Amazon Web Services (AWS) EC2 instances located in different availability zones. In front of these instances, an Elastic Load Balancer (ELB) is configured to redirect all HTTP requests on port 80 to HTTPS on port 443. Since the wp-config.php file was not updated to reflect this change, the requests were still using HTTP. To correct this, I updated the following values to use HTTPS:

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

However, this led to an endless redirection loop, eventually resulting in an error stating "too many redirections."


To resolve the issue, add the following line to the wp-config.php file:

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

This will fix the issue. Configurations like this can be challenging to troubleshoot, and you may spend many hours looking for a simple solution. Hopefully, this post will save you some time if you encounter this particular issue.

Profile picture

Software development professional with expertise in application architecture, cloud solutions deployment, and financial products development. Possess a Master's degree in Computer Science and an MBA in Finance. Highly skilled in AWS (Certified Solutions Architect, Developer and SysOps Administrator), GCP (Professional Cloud Architect), Microsoft Azure, Kubernetes(CKA, CKAD, CKS, KCNA), and Scrum(PSM, PSPO) methodologies. Happy to connect