Special offer
popup-offers
English
+370 5 205 5502 sales@monovm.com

How to redirect HTTP to HTTPS, How to Force HTTPS

If a website doesn't have an SSL certificate, then Firefox and Google Chrome shows "insecure warnings" when visitors load that website. SSL encrypted connection is necessary for the accessibility and safety of visitors to your website. 

11 Feb, 21 by Antoniy Yushkevych 4 min Read

How to redirect http to https in website, wordpress, laravel

It is also essential to redirect HTTP to HTTPS. Still, there is a way for forcing a website to load it into HTTPS (Hypertext Transfer Protocol Secure) rather than HTTP(Hypertext Transfer Protocol); by editing the .htaccess file. So this particular article will give detailed information on "how to force HTTPS" with step by step procedure.

 

What is SSL?

How to Redirect HTTP to HTTPS

Secure Sockets Layer is the full form of SSL, so it works for the security protocol for creating encrypted links between browsers and a web server for online communication. Your website will be available on HTTPS and HTTP after installing an SSL certificate in it. SSL makes sure that data transmitted between browsers and a web server always stays encrypted.  

Once you have the SSL certificate, install it on your website hosted by a VPS hosting. Hence, VPS hosting plays an essential role in creating a link between the SSL certificate and your website. 

 

How to Redirect HTTP to HTTPS using .htaccess File?

We will cover a detailed procedure to edit the .htaccess file and force HTTPS with steps for easy understanding (Ensure to create a backup of the website to eliminate major troubles).  So there are different ways of editing the .htaccess file for your website, and these ways are: 

  • You can edit the .htaccess file on desktop/laptop then upload it back on the server by FTP(File Transfer Protocol).
  • You can use the cPanel's file manager for editing a file.
  • You can use FTP's Edit mode that offers a way to edit a file easily or use an SSH(Secure Shell) and text editor for editing. 
  • You can use the cPanel file manager for editing the .htaccess file. 

 

How to Force HTTPS on the Particular Domain?

In case you have multiple domains, but a single domain requires force, use the below code. (We are writing a domain name as "domainxyz.com" in code so make sure you change it while copying for your domain name).

RewriteEngine On

RewriteCond %{HTTP_HOST} ^yourdomain1.com [NC]

RewriteCond %{HTTPS} off

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

After copying these codes, click on the save to make changes successfully. 

 

How to Force HTTPS?

You can use a function as the 301 redirects for .htaccess that can permanently redirect an old URL to the new URL. So use the following steps for performing it:

First, go to the File Manager of your hosting panel, open the public_html folder, and then select the .htaccess file.

Now, scroll down and find RewriteEngine On, then write the below codes in it: 

RewriteEngine On

RewriteCond %{HTTPS} off

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

Finally, save the changes to change HTTP to HTTPS quickly (Ensure that don’t repeat a line in RewriteEngine On because it can create significant trouble for your website).

 

How to Force HTTPS on the Particular Folder

You can use a .htaccess file to force HTTPS on a particular folder but make sure to place this file into a folder having an HTTPS connection. So use the following command to force HTTPS on the particular folder: 

RewriteEngine On

RewriteCond %{HTTPS} off

RewriteRule ^(folder1|folder2|folder3) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Ensure that you change a folder reference to the name of the actual directory. Once you make the changes, clear the cache of your web browser and connect to your website through HTTPS, and it will redirect you to HTTPS. 

 

Conclusion

This wraps our article on “how you can force HTTPS” quickly, and it can be a useful option if you want to change your website from HTTP to HTTPS. We have included the guidelines for multiple scenarios, so this article can help you to force HTTPS for specific conditions. Use this procedure if you face any issues while installing an SSL certificate on your website while using VPS hosting, then let us know in the comments.

Antoniy Yushkevych

Master of word when it comes to technology, internet and privacy. I'm also your usual guy that always aims for the best result and takes a skateboard to work. If you need me, you will find me at the office's Counter-Strike championships on Fridays or at a.yushkevych@monovm.com