I have had to move two WordPress sites from HTTP to HTTPS (https://www.rrosetta.com Â and https://magazine.AboutNewJersey.com) and both times I ran into the same problem – the site going into an infinite redirect. Â There was a key piece that was missed and not well documented so I figured I would put those steps down here and hopefully not only help myself in the future, but others as well.
WARNING: Before doing ANY OF THIS completely back up the website and database.
Update URLs in admin control panel
Go into the sites Admin Control Panel and go to Settings -> GeneralÂ there you will see these two fields that need to be updated to the new URL. Â Here instead of having http – you would put https.
Update URLs through the database
If you prefer to make the changes through the database Â you can go into the options table and manually change the siteurl column and the home column. Â This also comes in handy if you lose access to the Admin Control Panel and need to change the URLs back.
The Infinite Redirects
Once these changes were made, the website would not load and went into a infinite redirect. As it turns out Â it isn’t as simple to change a WordPress website from HTTP to HTTPS Â by merely changing the URLs.
Add elements to WP-Config
I needed to add the following to the wp-config file…
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') $_SERVER['HTTPS']='on'; define('FORCE_SSL_ADMIN', true);
They must be placed ABOVEÂ require_once(ABSPATH.’wp-settings.php’);
NOTE: I updated the formatting of the above code because WP automatically was changing the quote marks to slanted quotes and I didn’t realize it.Â
For more information –
WordPress – Administration Over SSL
At this point, while it was no longer getting the Â infinite redirect, f I put in http – it did not automatically redirect to https. Â Most of the recommendations I saw online to fix this issue involed modifications to the .htaccess file. However every one of the recommendations I tried caused an infinite redirect issue when using http. Â I then discovered this… “Cloudflare Support -Â How do I redirect all visitors to HTTPS/SSL?” It seems that since my site is utilizing Cloudflare a setting within Cloudflare itself has to be set – “Always use HTTPS”
After this fix my site was using HTTPS 100% of the time without any infinite redirect issues. Â Only one problem, the URL bar on Chrome was still indicating that my site was only partially secure and that there were still some items that were insecure. Â I fixed this by setting the “Automatic HTTPS Rewrites” setting to “On”.
Finally I had a fully secure website…
Now I discovered by using the Chrome developer tools that I had absolute links that still had http:// Â Even though the Cloudflare flag “fixed” this – I wanted to eliminate as many redirects and the rewriting of the URLs as possible, Â The Cloudflare setting should only be for a fallback in case there are any links you are unable to change. Â There is a plugin I found that will search for and update the URLs. Â It worked perfectly for me.