force SSL using .htaccess file

Security has become one of the most important concerns on the Web. Very often we skip visiting a Web Page just because it doesn’t have a SSL Cerificate. And most of the internet users do not share any of their credentials like email address with the Websites without a SSL. Here we’re going to show you ‘How to force SSL using .htaccess’

Step by step guide on How to force SSL using .htaccess:

To force all your visitors using SSL(Browse over https://) simply insert the following line of code in the .htaccess file located in your Website’s root directory.

Important Note: Do you have existing code in your .htacess file, add these above where there are already rules with similar prefix.

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

Be sure to replace www.yourdomain.com with your actual domain name.

To force a specific domain to use HTTPS, use the following lines of code in the .htaccess file in your website’s root folder:

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC]
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]

Don’t forget to replace yourdomain\.com with the domain name that you’re trying force to use SSL. Additionally, you must have to replace www.yourdomain.com with your domain name.

Want to force SSL on a specific folder? Then you should insert these lines of code below into a .htaccess file placed in that specific folder:

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

Make sure you change the folder reference to the actual folder name you want to send traffic. Don’t forget to replace www.yourdomain.com/folder with your actual domain name and folder you want to force the SSL on.

This is how you can force SSL using .htaccess.


We hope this tutorial helps you find the perfect solution. If your like our tutorials, definitely you’ll love our support. All VernalWeb hosting plans include 24/7 support from our amazing inhouse support staff. Check out our web hosting plans and have your website migrated today!

  • Was this article Helpful ?
  • yes   no

Leave a Reply