Redirect WordPress pages to https with htcaccess

Posted by Redirect WordPress http to https with htcaccess

This one has come in handy quite a few times for me. Often when you make a WordPress website https after previously being http, both versions still exists, but you no longer want people to be able to access the none secure version.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Where do I locate my .htaccess file?

You can find your .htaccess file inside the folder where you installed WordPress.

Connect to your server through cPanel or FTP (Filezilla is greatly recommended), and go into your WordPress folder. This is the folder where you find the wp-admin, wp-content and wp-includes folders. Usually you can find the .htaccess file right under those folders.

Copy and paste into your .htaccess file

Take the code from above and paste it into your .htaccess file. Remember to take a backup of your current .htaccess file, before changing anything. Paste the code into the top of your file, save and re-upload to your server. It will make sure that your website goes from http:// to https://.

Anything else I should do?

Save WordPress settings.

I would still make sure to change the WordPress Address (URL) and Site Address (URL) under Settings and General in the WordPress dashboard. Then go to Settings and Permalinks. We’ll just have to re-save the permalinks, so you scroll to the bottom of the page and press Save changes.

Search and replace the old URL

I always run a script as well, to make sure all my links work correctly. The script runs through your MySQL database, finds the old URL without https:// and replaces it for you.

Download Search and Replace by Interconnecit and extract the folder to your computer. Upload the folder to your server and put it in your WordPress folder next to the .htaccess file.

Open your browser and type in – the last part of your URL needs to be written exactly as the folder is named on your server.

Search and Replace DB script to replace old url with new

The page will look like the picture above. You will have to fill in your URL without https:// in the first field and your URL with https:// in the next field, so that it says replace with

First you press the Dry run button under Actions. If no error occours you press the Live run button. Once the script is done running, your press the Convert to utf8mb4 unicode. Finally, once that’s done, you press the delete me button. Very important to make sure that the script is deleted afterwards.

That’s it. Your website is now running https:// without the use of any plugins. If you’re using Google Analytics and Search Console, remember to add the https:// version in Search Console and edit your Analytics property to https://.

Leave a Reply

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