htaccess redirect HTTP to HTTPS – 5-minute tutorial

How to redirect to https

Hello everyone! today I’m going to show you how to htaccess redirect HTTP to HTTPS. This process is pretty simple and straight forward. However, just in case I suggest you make a backup of your htaccess file. This is due to the simple fact that you might overwrite something/delete something else already existent in the file without noticing. Resulting in a crash of your website. in short, make a copy 🙂

What is the htaccess file

Before I begin, I want to briefly talk about the htaccess file itself. You should know that the htaccess file is one of Apache’s configuration files. Furthermore, any error at that file will result in your website being down. If you don’t know what Apache is, well that a topic for a different article, however, in short, Apache is your web server. Anyhow, let’s continue.


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

As you can see, 3 lines of code to add to our htaccess file. However, if you’re using WordPress, you might have other stuff in your htaccess file, don’t be worried by these lines, just go ahead and paste your code in the following manner:

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

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

After pasting in the code, don’t forget to save the file and reload the page. That’s it, you are done.

To sum up our htaccess redirect HTTP to HTTPS article

I hoped my code snippet helped you in achieving what you set out to do. In addition to redirects, this file has enormous “JUICE”. Meaning, today we used it for redirects, however, it can be used in tons of other actions. Furthermore, I can’t stress this enough, today we made a simple change, despite that, I asked you to make a backup.

You should remember, before you handle this kind of configuration file, ALWAYS BACKUP BEFOREHAND! Moreover, if something doesn’t work, don’t panic, edit it again and see what you did wrong.

and finally, here’s some more htaccess articles: Htaccess Leverage Browser Caching, Apache Foundation

Leave a Reply

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