Redirect http to https by using htaccess

The use of SSL is a mandatory trend for websites, the need for correct configuration becomes more and more popular with many webmasters.

redirect http to https

After the installation of SSL on the host, the next step we need to do is to redirect http to https.

This work can do on Linux hosting using Apache by using .htaccess to redirect http to https.

Step 1: Open the .htaccess file at the root of hosting with the Filemanager host editor, or using an FTP tool. If you do not see .htaccess, you need to create one at the root folder.

Step 2: Copy and paste the code below, and save the file.

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://exampledomain.com/$1 [R=301,L]

Please notice if you want to redirect http:// and http://www into https://www., you just need to add www. in the code in .htaccess. Also, you can use the code below:

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

And, remember change the exampledomain.com into your domain name.

After that, delete the cache and refresh your website. Url with https will work well.

In case, you want to redirect a wordpres website from http to https. You need to do more more step. Login into your dashboard of website, navigate to Settings – General. Then, you type the domain main name with https into WordPress Address (URL) vaf Site Address (URL). Save it! Done!

wordpress http to https

I hope you can redirect http to https for your URL with .htaccess file correctly and run it smoothly.

About the author

Thom Ho

Mr. Thom has worked as an SEO specialist and WordPress developer, and he is on the list of the top 15% SEO workers in the world, tested by Linkedin in Nov 2020.

Leave a Comment