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 %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
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] RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [L,R=301] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.php [NC,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 %{HTTPS} off RewriteRule ^(folder1|folder2|folder3) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Make sure you change the folder reference to the actual folder name you want to send traffic. Don’t forget to replace the folder name 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!