How to Force HTTPS on Your WordPress site

In this tutorial I will explain how you can easily force HTTPS on your WordPress site. I will show you the trick to enabling https on the entire domain, on a sub-domain and on a single page. You don’t even need to use any plugin for this.

This tutorial will be very helpful if you have purchased an SSL certifiate for your WordPress site but you don’t know how to force your webpages to use HTTPS URL.

Enabling HTTPS on the Entire Domain

Edit the .htacess file in the root of your WordPress site (it should be in the “public_html” directory) and then add the following snippet of code:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.your-domain.com/$1 [R,L]

Replace “your-domain.com” with your actual domain name. If you don’t want to use the keyword “www” then remove that too.

The above will make it so when anyone is trying to access any page on your site using the Non-HTTPS URL, it will automatically redirect to the HTTPS URL.

Enabling HTTPS on a Sub Domain Only

What if you wanted to just enable HTTPS on a sub-domain (not the main domain)? Edit the .htacess file in the root of your WordPress site and then add the following htaccess code to the file:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(sub-domain)\. [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

Replace “sub-domain” with your actual subdomain name/keyword.

Enabling HTTPS on a Specific Page Only

You may need to enable HTTPS on a single/specific page (example: your checkout page). Edit the .htacess file in the root of your WordPress site and then add the following htaccess code to the file:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} directory
RewriteRule ^(.*)$ https://www.your-domain.com/specific-page/$1 [R,L]

Replace “your-domain.com/specific-page” with your actual page URL.

Redirect Using a WordPress Plugin

You could also redirect users automatically to the HTTPS version by using this WordPress plugin.

Now, you know how you can force pages on your site to the HTTPS URL easily.

Leave a Reply

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