Victor Leung
Victor Leung
BlogAI SolutionAlphaAlgoFlower shopFX CombineIEESushi ClassifierWealth Agile

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.

About Victor Leung

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

Continuous improvement

Copyright © 2023.