I setup a Cloudflare Tunnel and changed the URL for WordPress from an IP address to a domain name. After that, the frontend worked fine, but the wp-admin folder and wp-login.php were getting too many redirect errors. I made sure that the SSL certificate was correct. I checked to see if it was going to https and not http. I checked to see that the certificate was getting set to the right directory on the server. Finally I decided to get a new certificate, but even that did not fix the redirect error. I did finally figure out the solution though. In the wp-config.php file, I added this right before /* That’s all, stop editing! Happy publishing. */:
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
$_SERVER['HTTPS'] = 'on';
}
What does it mean? Well first it checks for the HTTP_X_FORWARDED_PROTO header and then checks if it equals https. If it does, then it tells WordPress to use https and forces the redirect to go to https. This will break the redirect loop.
