Switching a WordPress Site From HTTP to HTTPS

  • Website
  • Published Jan 15, 2015 Updated Mar 18, 2018

Using SSL for the entire website should be the norm these days. If you have a decent server it does not significantly reduce page speed and it allegedly even helps your Google ranking. I covered enabling SSL and configuring it so that you get an A ranking in the Qualys test in another post. This article shows how to convert an existing WordPress site from HTTP to HTTPS.

Qualys SSL test - helgeklein.com

Basic Steps

The following three steps are required in order to switch your entire WordPress site to HTTPS:

  1. Set up SSL in your webserver configuration. This article explains how to do that for Apache.
  2. Replace every occurence of http://yourdomain.com with https://yourdomain.com in the WordPress database
  3. Redirect to HTTPS

Let me explain steps two and three in detail, but please make sure you have a full database backup before you try this out!

Search and Replace in the WordPress Database

Wouldn’t it be cool if you could search and replace in the WordPress database without having to deal with SQL imports and exports? Thanks to WP-CLI, a command line interface to WordPress, you can! Many thanks to Nicholas Dille for making me aware of this nifty utility!

Install WP-CLI

Install WP-CLI as follows:

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

Check if WP-CLI works correctly:

wp --info

Replace HTTP with HTTPS

Navigate to your WordPress directory (you need to use your own path, of course):

cd /var/www/helgeklein.com/public_html/

Dry Run

Test the replace command by appending the dry-run parameter. Notice how we skip the guid column.

wp search-replace 'http://helgeklein.com' 'https://helgeklein.com' --skip-columns=guid --dry-run

The Real Thing

This DOES modify your WordPress database!

wp search-replace 'http://helgeklein.com' 'https://helgeklein.com' --skip-columns=guid

Caching Plugins like W3 Total Cache

If you are using a caching plugin like W3 Total Cache delete the cache now. You should also configure it to not cache the (RSS/atom) feeds. Although that would be good for performance W3TC 0.9.4 inserted a head element before the rss tag which broke the feed.

Redirect to HTTPS

With these simple configuration changes, HTTPS is already fully configured. WordPress automatically redirects HTTP requests to HTTPS. For good measure and possible slightly improved performance redirect at the (Apache) server level. Put this in your virtual host configuration:

# HTTPS everywhere
RedirectPermanent / https://helgeklein.com/

Subsites

If you have a multisite installation it may be necessary to update the subsites’ siteurl and home settings. You can do that through the WordPress UI by checking the corresponding checkbox:

WordPress subsite - update siteurl

Comments

Related Posts

Guide: WordPress on Dockerized Apache on Hetzner Cloud

Guide: WordPress on Dockerized Apache on Hetzner Cloud
If you’ve followed this blog for a while, you may have noticed that I’ve used a traditionally installed (i.e., not dockerized) LAMP stack for its server setup since 2014. Only recently did I switch to Docker containers. Why? Maintenance. Much facilitated maintenance. If you take a look at the articles I’ve written over the years describing how to upgrade to newer versions of Ubuntu or - god beware - PHP, you can’t help but realize what a godawful PITA it all is. Switching to Docker enforces (or at least strongly encourages) a strict separation of (public) code and (personal) configuration. With this new setup, upgrading from one PHP version to another involves nothing more than changing a version number in a text file.
Website

Latest Posts

Fast & Silent 5 Watt PC: Minimizing Idle Power Usage

Fast & Silent 5 Watt PC: Minimizing Idle Power Usage
This micro-series explains how to turn the Lenovo ThinkCentre M90t Gen 6 into a smart workstation that consumes only 5 Watts when idle but reaches top Cinebench scores while staying almost imperceptibly silent. In the first post, I showed how to silence the machine by replacing and adding to Lenovo’s CPU cooler. In this second post, I’m listing the exact configuration that achieves the lofty goal of combining minimal idle power consumption with top Cinebench scores.
Hardware

Fast & Silent 5 Watt PC: Lenovo ThinkCentre M90t Modding

Fast & Silent 5 Watt PC: Lenovo ThinkCentre M90t Modding
This micro-series explains how to turn the Lenovo ThinkCentre M90t Gen 6 into a smart workstation that consumes only 5 Watts when idle but reaches top Cinebench scores while staying almost imperceptibly silent. In this first post, I’m showing how to silence the machine by replacing and adding to Lenovo’s CPU cooler. In a second post, I’m listing the exact configuration that achieves the lofty goal of combining minimal idle power consumption with top Cinebench scores.
Hardware