Published: 04 Dec 2018 › Updated: 04 Dec 2018
Moving a WordPress Website from HTTP to HTTPS: A Complete Guide
For the longest time, the Search Engine Journal WordPress website ran on an HTTP connection. We decided to migrate to HTTPS after Google confirmed that websites would not lose rankings when moving from HTTP to HTTPS.
Just recently, Google set July 2018 as the deadline for HTTPS implementation. The company warned publishers that, for any HTTP domains, Chrome will display a “not secure” label in the address bar.
This means migrating to HTTPS is important now more than ever.
In this post, I will share the experience I had from migrating the SEJ website to HTTPS and many other WordPress-based websites I’ve worked on.
I’ll be assuming you have basic WordPress coding skills and have already installed an SSL certificate on your server, since most hosting providers offer that feature with one click.
WordPress Website Structure: An Overview
Before starting, here’s a basic overview of how WordPress websites are structured.
Every WordPress website has the following file structure:
Fig. 1
Fig. 2
- Images
- JavaScript files
- CSS files
- Internal URLs used in CSS/JavaScript files
- iframes
- Videos
- Audio
- Form actions
- Fonts
- Search & Replace in Files
To begin, search for instances of your domain pointing to HTTP URLs of your site.
Use the regex for “www” and without “www” URL cases and search forhttp://(www.)?yourdomain.com
Fig. 3
Fig. 4
Fig. 5
get_home_url()."/some2.js". This will ensure that the correct source link will always be displayed.
I am just pointing out a worst-case scenario since you may have custom themes or plugins badly developed with hardcodings. It is not a recommended way of programming yet happens quite frequently.
Next, you’ll also have to take care of HTTP resources pointing to external domains.
To do this, you’ll need to search for the string http:// in your Plugins and Active Theme folders (in our case “auto-repair” ) files but as a whole word match (see: Fig. 4).
Here is how it looks in my code editor:
Fig. (6)
Fig. (7)
Fig. 8
- Forms actions, example:
<form action="http://example.com/">you can search for action=”http:// - Fonts/CSS files, example:
<link rel="stylesheet" type="text/css" href="http://example.com/>you can use this regexp<link * href="http://for searching.
- Search & Replace in the Database
First, you’ll have to download search and replace database tool.
Upload it to your server in a long random folder name (e.g., “replace879846513134984451”) because if someone accidentally finds it, there is a security risk.
28 Experts on the Top 2019 PPC Trends You Need to Know [Ebook]
Learn the top 2019 PPC trends you need to know according to 28 of the smartest industry practitioners. Get your free ebook now!
ADVERTISEMENT
If you navigate to yourdomain.com/replace879846513134984451 URL, you will see the following:
Fig. 9
http:\/\/(www\.)?yourdomain\.com for “www”(http://www.yourdomain.com) and without (http://yourdomain.com ) URL cases.
Fig. 10
Fig. 11
http:\/\/(www\.)?youtube\.com with https://www.youtube.com, http:\/\/(www\.)?vimeo\.com with https://www.vimeo.com etc.
For resources other than the well-known domains, there is no way to import them automatically since they are usually large files. You need to search for those in the database by performing custom SQL query to find and fix them manually.
Here is a code snippet you can run to extract all posts which contains src=”http://”.
global $wpdb; $results = $wpdb->get_results( "SELECT ID FROM ".$wpdb->posts." WHERE ( post_content LIKE '%src=\"http://%' OR post_content LIKE \"%src='http://%\" OR post_content LIKE '%src=http://%' ) AND post_status = 'publish' and post_type = IN('post','page') order by post_date desc", OBJECT );
foreach ( $results as $post ) { echo get_permalink($post->ID).'<br/>';}
(Note: You can add post types to the list IN(‘post’,’page’), separated by commas, in case you want to run this over custom posts types. For example in case of WooCommerce you may add also “product” to scan products content.)
After you run this query you will get a list of all posts that have HTTP source and mixed content issue.
Generally, after you finish it is always good to sanity check and run this query to make sure you didn’t leave any instances with HTTP resources.
Also, it is always good to browse the website for a while manually and check via the Google Chrome Console whether it is clean.
When you are sure everything is done right, the final step is to set up 301 redirects from HTTP URLs to HTTPS.
- Implement Redirects
If your server runs on Apache, here is the code you can put in your .htaccess file.
Be careful when implementing this step – any mistake in a command can break the website.
Put this code at the most top
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
Alternatively, you can use Easy HTTPS Redirection plugin.
4. Update CDN If you use a CDN, there should be a URL setting similar to Google Analytics where you can update your website to an HTTPS version. The migration for each CDN is different and you need to check your CDN provider documents or contact support for details how to do that.
- Changing URL in Google Analytics
You need to change in Google Analytics “Website’s URL” settings in Admin > Property > Property Settings and Admin > View > View Settings.
Fig. 12: Website URL Setting
Fig. 13: Add a property in Search Console
Fig. 14: Re-submit sitemap
Fig. 15: Disavow Links
Posted from my blog
Leave Moving a WordPress Website from HTTP to HTTPS: A Complete Guide to:
Read more #http posts
Best Posts From TechVHow
We have not curated any of techvhow's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From TechVHow
- How to Install and Setup WordPress Multisite Network
- What is a Multisite Network in Wordpress
- How to Add a Mega Menu on Your WordPress Site (Step by Step)
- Enabling HTTPS Without Sacrificing Your Web Performance
- OnePlus 6T McLaren Edition with Warp Charge 30, 10GB RAM launched in India at Rs 50,999
- 12 Best Drag and Drop Page Builders for WordPress 2018
- A WordPress Tutorial for Beginners: Create Your First Site in 10 Steps
- Debunking mouse myths
- How to install Ioncube Loaders – simple steps for various hosting types
- OnePlus 6T McLaren Edition pre-registrations go live on Amazon