Config WordPress behing a proxy (like Cloudflare)

When WordPress is behind a proxy, like Cloudflare, that handles SSL and is hosted without a certificate, it can get infinite loop redirects.

To solve this you can add following snipped in wp-config.php file.


if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) {
	$_SERVER['HTTPS'] = 'on';
}

I think this setup is becoming so common this could be in wp-config by default.

For more information you can see: https://developer.wordpress.org/advanced-administration/security/https/#using-a-reverse-proxy

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *