title: Infinite loop Wordpress 301 redirect AWS CloudFront Load Balancer and LightSail
body: <p>I have a CloudFront, LightSail Load Balancer and LightSail instance hosting Wordpress under <code>/blog/</code> endpoint.</p>
  
  <p>In Lightsail Load Balancer there is only HTTP option to connect to the instance so the traffic is now</p>
  
  <p>HTTPS -> CloudFront -> HTTPS (different Domain) -> Origin Load Balancer -> HTTP -> LightSail Instance</p>
  
  <p>The LightSail instance does a redirect to https with below settings in <code>wp-config.php</code></p>
  
  <pre><code>if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false)
         $_SERVER['HTTPS']='on';
  
  define('WP_HOME','https://www.test.com/blog');
  define('WP_SITEURL','https://www.test.com/blog');
  </code></pre>
  
  <p>However this creates infinite loop.</p>
  
  <p>How can we change the settings so it doesn't do the loop?</p>