Too many redirects after switching to HTTPS
Tutorials
You flip your WordPress site over to HTTPS, everything looks fine for a minute, and then the browser gives up: "too many redirects". Nine times out of ten, Cloudflare is sitting in the middle of it.
Here's what's happening. With Cloudflare's SSL mode set to Flexible, visitors connect to Cloudflare over HTTPS, but Cloudflare talks to your server over plain HTTP. Your server sees an HTTP request, WordPress (or your redirect rule) bounces it back to HTTPS, Cloudflare fetches it over HTTP again, and round and round it goes.
There are two ways out.
1. The proper fix: Full (Strict)
In Cloudflare, go to SSL/TLS and switch the mode from Flexible to Full (Strict). Your server needs its own SSL certificate for this – a free Let's Encrypt one is fine, and most hosts will issue it in a click or two. Cloudflare now talks HTTPS to your server all the way, so there's nothing left to bounce.
2. The quick fix: tell WordPress it's already on HTTPS
If you're stuck on Flexible for whatever reason, add this to wp-config.php, above the /* That's all, stop editing! */ line:
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
$_SERVER['HTTPS'] = 'on';
}
Cloudflare passes the visitor's original protocol along in a header. This checks that header and stops WordPress from redirecting a request that was already secure.
Go with Full (Strict) if you can. Flexible means traffic between Cloudflare and your server travels unencrypted, which defeats a fair chunk of the point of switching to HTTPS in the first place.
Source: StackOverflow