How To Force SSL Using .htaccess File?

How To Force SSL Using .htaccess File?

Security has become one of the foremost important concerns on the website. fairly often we skip visiting the web page simply because it doesn’t have an SSL Certificate. And most internet users don’t share any of their credentials like an email address with Websites without an SSL. Here we’re getting to show you ‘ How to force SSL using .htaccess File ’

How To Force SSL Using .htaccess File

How to force SSL using .htaccess?

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

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

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

To force a selected domain to use HTTPS, use the following lines of code within 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 exchange yourdomain\.com with the domain name that you’re trying to force to use SSL. Additionally, you must get to replace www.yourdomain.com together with your name.

Want to force SSL on a selected folder? Then you should insert these lines of code below into a .htaccess file placed in this 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 with regard to the particular folder name you would like to send traffic. Don’t forget to exchange www.yourdomain.com/folder with your actual domain name and folder you would like to force the SSL on.

This is how you’ll force SSL using .htaccess.

Also Read: How to Redirect HTTP to HTTPS Using. htaccess?
Also Read: How To Create Or Edit Htaccess File In cPanel?

SSL Certificate

We have listed many hosting provider Companies’ plans. Go and book the best SSL plan for your website.

Create A Beautiful Website

You want to create a website for your business click the below button.

Buy Best Hosting For Website

Hostguid listed many hosting plans so you can easily compare many hosting companies hosting packages for your website.

Join Our Whatsapp Group

Upcoming hosting and SSL offers and news updates here. We can try to solve your doubt regarding any problem like Domain, Hosting, SSL certificate, etc. And News update here.

Join Our Telegram Group

Upcoming hosting and SSL offers and news updates here. We can try to solve your doubt regarding any problem like Domain, Hosting, SSL certificate, etc. And News update here.

This article helpful?
YesNo
Default image
Host Guid
Articles: 55

Leave a Reply

Open chat
1
Hii, How can I help you?