Fix: Cloudflare Redirect Loop and Other SSL Issues

Fix: CloudFlare Redirect Loop and Other SSL IssuesThere is an easy solution for the SSL issues you’re having after enabling Cloudflare SSL.

CloudFlare Endless Redirect Loop Error

After enabling Cloudflare SSL on your site, You might get some issues like,

  • Site not secure or Invalid SSL Warnings
  • Your WordPress site going into Endless Redirect Loop
  • WordPress wp-admin going into Redirect Loop

Or any similar issue or errors. They are all caused by enabling Cloudflare SSL.

You must have tried to find a solution using Google, but most of the websites and forums are providing solutions that simply don’t work.

I was in the same situation as you are, Stumbling through countless sites and forums trying to find a fix so my website can open.

I also contacted my hosting provider but they asked me to wait 24 hours. But I knew there was some issue, And even after 24 hours, the issue was there.

In some cases, the solution is simply to change SSL status from Full to Flexible on Cloudflare. But that doesn’t solve the issue for most.

But for some reason, anyone you ask for help will ask you to make sure that it’s set to Flexible, Even though it’s already set to Flexible. That makes you frustrated on finding the cause behind this.

But do not worry, we have an easy fix for the WordPress redirect loop on Cloudflare SSL or any other Cloudflare SSL related issue you’re getting.

Now without wasting any more of your time,

Here is the fix that will resolve the Cloudflare SSL issue you’re having:

First, Edit wp-config.php file from your WordPress root through Cpanel or FTP (whichever is your preferred method for editing files).

Now in wp-config.php, Locate this line:

/* That’s all, stop editing! Happy blogging. */

Now before this line, Add the following line:

$_SERVER['HTTPS'] = 'on';

And save the wp-config.php file.

For example, This is what my wp-config.php file looks like:

wp-config.php CloudFlare Redirect Fix

Now go ahead and try to load your site again. In most cases, it should load normally without any issues.

This solution should fix the Cloudflare Redirect Loop issue instantly.

But if you still have any issues, you can comment below and we’ll try to help you further.

Web Hosting
  • Pupparazzi says:

    Thanks so much for this. I was having some issues with cloudflare and the SSL resolving correctly. As you suggested in an earlier comment I tried switching my settings to Full SSL in the Cloudflare account and it seemed to fix all my issues. Thanks for your advice – it saved me alot of hassle!

  • Rodrigo says:

    THank you solved it for me.

  • warhammer says:

    Totally work for me ! Thx !

  • eArtisan says:

    Sir, you truly are a lifesaver!

  • Tim says:

    Thanks Vinod, this worked for me. I’m still baffled by this bug tho. It doesn’t happen on every WP + Cloudflare site. Have you since figured out who is to blame? WordPress, our hosting providers, or Cloudflare?

    • Vinod Bokhiriya says:

      You’re welcome, Tim. Thanks for the comment. It seems like an issue with some hosting providers’ systems as CloudFlare SSL is not the traditional SSL that works from the server side.

  • Ajay says:

    It worked. However, I was using own 3rd party CA certs (not cloudflare shared) and now if I turn off SSL in Cloudflare, website goes down. If I turn it on, then I am forced to use Cloudflare’s shared SSL. If you can help out how one can use Own Certs, it would be helpful. Thx.

    • I’m not sure why you’re getting that issue, you should contact your hosting provider or Cloudflare, they should be able to help you out.

  • David Savage says:

    Thanks Vinod!

  • Guest says:

    It worked thanks man! You are great

  • Michelle says:

    I was so hopeful your solution would work for me but unfortunately it didn’t. My website is stuck in the redirects loop and Cloudflare aren’t being much help. I have Flexible SSL with ‘always use https’ on, as advised elsewhere I contacted my origin host (Bluehost) to remove the http redirection from their end. And I’m still stuck! Any advice would be much appreciated! 🙂

    • I have found that using Flexible SSL on CloudFlare with Bluehost causes this issue as well. So you could try using Full SSL instead and that will most probably resolve the issue.

      • Select says:

        Thanks! Full SSL fixed issue, surprising since Flex is the “lighter” less-strict setting.

  • ian says:

    Thanks for this, this fixed my issue instantly.