I am using nginx as my webserver and i have edited the configuration file to point to https, so i change the WordPress url settings to https and also added the WordPress force ssl admin code to my wp-config file but I keep running into the error "This webpage has a redirect loop"

enter image description here

You've added $_SERVER['HTTPS'] = 'on'; to your wp-config.php?

You should also use the WP Migrate DB plugin to migrate from http://yoursite.com to https://yoursite.com

  • 7
    I would give you a 1000 upvotes for this! – Sheharyar Jan 17 '16 at 21:56
  • 3
    For some reason, this vital step is so often not included. – Tania Rascia Jan 27 '16 at 6:47
  • 3
    Thank you! That probably saved me a few more hours of trying to figure out why the admin area wasn't working with SSL. – Sledge Hammer Feb 20 '16 at 17:42
  • 2
    wow! $_SERVER['HTTPS'] = 'on'; saved me! – PJunior Feb 3 '17 at 17:13
  • 1
    Why does this work? I already used Interconnect's S&R tool. I should already have the right protocol in the database. – Jeff Feb 15 '17 at 20:28

I had a similar problem and just added the following snippet to my wp-config.php:

/** SSL */  
define('FORCE_SSL_ADMIN', true);  
// in some setups HTTP_X_FORWARDED_PROTO might contain  
// a comma-separated list e.g. http,https  
// so check for https existence  
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false)  
    $_SERVER['HTTPS']='on';

as suggested in the Codex. This will only be needed in case there's SSL passthrough enabled in your load balancer (or firewall) setup. Meaning that while you can access the site via HTTP within TLS/SSL, the communication that your server receives is HTTP only. To account for that, above header is needed so WordPress can "set" HTTPS to on in the $_SERVER config array.

  • 2
    This is great solution specifically for anyone using a load balancer. I was hosting this using Dokku (a host-it-yourself clone of Heroku) and having problems with static resource loading and the wp-admin redirect loop. Dokku also does an nginx reverse proxy to forward incoming 443 traffic to port 80 and this fixes the issue. – ZachM Jun 6 '16 at 14:54
  • 2
    I had to just put the $_SERVER['HTTPS'] = 'on'; because HTTP_X_FORWARDED_PROTO is not even in the settings on my client's server :| – Tom Roggero Jan 23 '17 at 17:11
  • 1
    Fixed my issue perfectly when using an AWS load balancer. – Josh Apr 12 '17 at 15:27
  • This also fixed the "Too many redirect issue" as my site is behind a load balancer on AWS. – voam Nov 1 '17 at 19:24
  • I think is important to add to this answer the fix for the .htaccess file for such cases: stackoverflow.com/questions/36748110/…, check @harshal-lonare answer. – Gustavo Jantsch Oct 5 at 15:29

As I do not have the comment privilege yet, I will post this addition as another answer:

The solution proposed by Elias, to add the following to wp-config.php, did the trick for me:

/** SSL */  
define('FORCE_SSL_ADMIN', true);  
// in some setups HTTP_X_FORWARDED_PROTO might contain  
// a comma-separated list e.g. http,https  
// so check for https existence  
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false)  
    $_SERVER['HTTPS']='on';

However, it only worked for me when I put it before everything else in this file!

  • This was exactly what my problem was. I had put these at the end of the file and it wasn't working. I was ready to rebuild my site from scratch. Moved them to the top and bam, issue fixed. Thank you, Thank you!! – Dean Poulin Feb 3 at 2:19
  • This solution is great if you're using a flexible SSL behind a proxy DNS like Cloudflare. Thank you. – Stefan P Feb 16 at 5:44
  • Confirmed working. Thank you so much, this fixes a lot of problems we had with API's and IFrames. The site doesn't have HTTPS enabled, but we need some pages to have it on. Wordpress should have this as a setting by default... – Andy Apr 25 at 14:25

Another version for the books, just add this to the top of wp-config.php

Reason is that there could be load balancers or something that does not pass along the proper https value, so you have to grab it from elsewhere and fake it for wordpress.

if ( (isset($_SERVER['HTTP_X_FORWARDED_PORT'] ) && ( '443' == $_SERVER['HTTP_X_FORWARDED_PORT'] ))
    || (isset($_SERVER['HTTP_CF_VISITOR']) && $_SERVER['HTTP_CF_VISITOR'] == '{"scheme":"https"}')) {
    $_SERVER['HTTPS'] = 'on';
}

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.