WordPress 4, HTTPS and Tsohost, it all works

problemsolvedWell, it turned out to be very simple in the end, all I had to do was ask for help.  A week ago I setup my WordPress blog on Tsohost to use SSL, and I explained why in my subsequent blog.  At the time I was running WordPress version 3.9.2, and when version 4.0 was released I decided to upgrade.  What I ended up with was the dreaded ‘redirect loop’, and I’ve spent a few hours over the last three days trying to work out what went wrong.  Eventually, I gave up, and asked my hosting provider to help, and precisely 8 minutes later, it was fixed.

So what on earth happened?  Well, I’ll set out the sequence of events (with my limited understanding, which is probably helpful to anyone who is running a WordPress blog on Tsohost who isn’t a PHP expert);

  1. I ran the update to WordPress 4.0, which had worked on my other site, and got the error “Firefox has detected that the server is redirecting the request for this address in a way that will never complete”.  What this means is something on my blog was directing visitors (me included) to a place where they were then directed back to where they came from, and so on, ad infinitum.
  2. I restored my blog files and database from backup, and ran it again, just in case this was a one off, which it wasn’t.
  3. I did a bit of research, and found the most likely causes of this were; incorrect Home and Site URLs, poorly written plugins, or  .htaccess based redirections conflicting.
  4. I checked the Home and Site URLs, deactivated and then deleted any redirect related plugins and checked all the .htaccess files I could find.
  5. Still no joy, so I tried reverting my site to HTTP, re-tried the upgrade (which worked), then set it back to HTTPS, and back came the redirect loop.
  6. Finally, I ran a complete backup of my site using the very useful Duplicator plugin, dumped an export of all posts using the WordPress export to XML function, deleted all the files and the database, and started from scratch.  Same result.
  7. At this point I did some pretty fruitless internet searches until I realised there was nothing I could access which could be effecting the problem, and it was either a PHP code bug (unlikely) or something under the control of my hosting provider, Tsohost, so I logged a Support Ticket.
  8. Just over 8 minutes after I submitted the ticket, it was fixed.  What the hell had I been doing for the past three days?!

The resolution

I wouldn’t say it was simple, the issue was that Tsohost (as a cloud provider) runs an SSL load balancer, which means the way it handles incoming HTTPS requests is not the same as a single server would.  The fix which Boriana at Tsohost Support very kindly implemented for me was the addition off the following code to the index.php and wp-config.php;

if($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') { $_SERVER['HTTPS'] = 'on'; $_SERVER['SERVER_PORT'] = 443; }

That did it.  I’ve now added all the plugins back in (it turns out I didn’t need some as new Jetpack features have rendered them obsolete) and the site is working even better than before.  Every time I call upon Tsohost for any assistance, whether it’s technical support, an upgrade, billing or new services, they excel.  I have never worked with such a consistently excellent service provider before, and long may they last!

2 thoughts on “WordPress 4, HTTPS and Tsohost, it all works

  • November 13, 2014 at 8:45 am

    Thank you Richard!

    I was up all night trying to fix this ready for launch today but your post has saved my life 🙂

    I’m also with TSO – i cannot fault their service they have been excellent!


Leave a Reply

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