Having problems accessing the admin over https when it’s setup behind CloudFront Flexible SSL.
The admin works fine when accessing over http, but as soon as I change to secure https it ends up in a redirect loop.
I’m adding the following line to wp-config.php
to force SSL in the admin.
define('FORCE_SSL_ADMIN', true);
This is due to the fact that CloudFlare’s Flexible SSL operates as a reverse proxy and connects to the WordPress installation via
http
. WordPress thinks you’re connecting viahttp
and does a redirect to thehttps
resource. The browser requests thehttps
resource from CloudFlare and CloudFlare again requests the resource overhttp
from the WordPress server, resulting in another redirect.Fortunately there’s a solution. CloudFlare sends an http header X-FORWARDED-PROTO that is the protocol used in the connection from the browser to the CloudFlare server. We can use this to tell WordPress that even though the request is happening over
http
, the link to the browser is overhttps
.In the
wp-config.php
file add the following line:It’s also crucial that the above line comes before the following line:
After making that modification the redirect loop will stop and you’ll be able to use the admin again.
This ultimately applies to all reverse proxy servers, not just CloudFlare.
In my case we getting this problem because I configure CloudFront origin incorrect.
after this setting my website working fine
in my case, another source of problems was (I know sounds silly) the DefaultRootObject.
I had this error on my CloudFront and WordPress and was the issue of my Too Many Redirects nightmare. I’m posting that because someone falls into the same stupid error like me.
Cheers