Tip: easily redirect all website traffic from http to https with htaccess

This is a long stroy short. If you are looking for an easy way to redirect all your website traffic from http to https, doing it via adding a rule in your htaccess is one possibility.

For this to work you need to have an SSL certificate installed at your webhost (this post is applicable to websites hosted at a shared hosting environment running on Apache web servers). Most likely, let’s say if you are hosting on HostGator or any of the big ones, the SSL cert is automatically available or just needs to be turned on via your hosting control panel. Once you have a certificate installed, it’s just a matter of redirecting the traffic.

How to redirect web traffic from http to https via htaccess rule?

It is fairly easy. All you need to add to your .htaccess file is the following piece of rules:

RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://ipaadress.ee/$1 [R,L]

So it would look like this. Bare in mind you may already have other rules present in your htaccess file, so make sure you don’t cause any conflicts (trial and error can help you there, too).

Redirect web traffic from http to https with htaccess rule
Redirect web traffic from http to https with an htaccess rule

 

Note 1: the .htaccess file sits at the root of your web folder. If you cannot see it in let’s say cPanel’s file manager, you need to enable viewing hidden files (dotfiles). To do this open Settings at top-right of the cPanel file manager and tick “Show Hidden Files (dotfiles)”. .htaccess is a dotfile, to see it, this setting must be on.

Show hidden files (dotfiles) in cPanel file manager to see .htaccess
Show hidden files (dotfiles) in cPanel file manager to see .htaccess

Note 2: once you have forced all your traffic to go to https version of your site, you should also make sure that your website canonical URL is correctly https and that you have the https version of your site set up at Google Webmasters.

 

Post Author: Tom Pai