If you find this post it means you’ve attempted all other tutorials about “How to Fix Too Many Redirects in WordPress” and you’re probably pulling your hair out, or what’s left of it.

Well there’s one thing pretty much every other tutorial leaves out, and I’m going to save your day and make your pain go away.

If you experienced the too many redirects error after installing WordPress with https enabled and then you change the http to https in general settings then this is probably the fix you need, but only if you’re using an nginx ssl terminator to an Apache http localhost.

You’ll know whether you are or not because in your nginx host file you’ll have this, and if you don’t have it then that could be one more reason your stuff is broken:

proxy_set_header X-Forwarded-Proto https;

So if clearing your cookies and cache doesn’t work like every other tutorial tells you and the above nginx  setup sounds familiar then edit your


file and add this code to it just after the comments section.

if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') $_SERVER['HTTPS']='on';

and you’re done, give it a try now and see whether the redirect loop is fixed.

I hope it fixed your redirect loop, I know how frustrating it can be!

Next: Cloud Hosting and a Powerful New AI called Maxine


  1. Exactly as you said, after struggling with all other tutorials, this was the one that saved my day. Thank you very much!

  2. OMG. YOU FIXED IT! I’m seriously pulling my hair out. I CAN’T BELIEVE this worked! NOTHING else did! THANK YOU THANK YOU THANK YOU!!!!

  3. You know what….! You are a genuis! I was really pulling my hair out, and just a simple line of code fixed it!!!! Thanks a bunch buddy!

    Arador – Thank you a 1000 times!

    Like everyone here trying to update the siteurl , homeurl and even the htaccess nothing worked. This did!
    Great explanation on why and then the fix!

  5. The provided solution didn’t help for me. However, I’ve come accross another blogpost, which recommended to disable the template redirect filter in WordPres – that did the fix for me:

    // insert this line in functions.php
    remove_filter(‘template_redirect’, ‘redirect_canonical’);

  6. Thank you for this fix, especially since my WP site is running on Linux and I’m using Nginx as a reverse proxy.

    I’m bookmarking this page. I appreciate you. Happy New Year to you and yours.

  7. I looked high and low and tried everything to get my wp admin login to stop redirecting too many times …
    I was about to give up when I found your code and wah-la it worked !!
    Thank you – Thank you !! Your a Gem!

  8. Yet another site saved with this advice! In my case, it had something to do with CloudFlare adding SSL, but this trick fixed it.


  9. Thank you! It is the year 2020 and this still works

    I am using a Load Balancer on AWS Lightsail and I am trying to use HTTPS on the load balancer with a Apache redirect.

    This finally fixed the issue after I tried everything else.

    Thank you for posting this!


  10. Thank you, thank you, thank you. 5 days of trying to fix a site (which had been workign with SSL but was switching to all https and finally fixed. Thank you.

  11. You are just life Saver, I reinstalled wordpress again and again why think why the hell its not working, Just love you man <3

  12. Thank you so much, Arador! I’ve been working with WordPress for 10+ years and never saw this strange error until today. Your fix is the only one that worked! Bless you!

  13. I don’t usually take the time to comment on posts… but you’ve saved me a considerable amount of time and for this I thank you!

  14. Awesome!! Just want to share one experience, in my case, i had to move it a little down the config file as it gave me a http 500 when i put it right on top, after the comments section


    define(‘WP_SITEURL’, ‘https://www.mydomain.com’);
    define(‘WP_HOME’, ‘https://www.mydomain.com’);
    if ($_SERVER[‘HTTP_X_FORWARDED_PROTO’] == ‘https’) $_SERVER[‘HTTPS’]=’on’;

    After that, worked like a charm, spend 2 hours messing with this, THANK YOU!


Please enter your comment!
Please enter your name here