Knowledge Base
MilesWeb / SSL Issues & FAQ

Steps to Force SSL Using the .htaccess

Approx. read time : 2 min

SSL certificate plays a significant role on your website. It helps to build the trust of your visitors as well as encrypts the data that is shared by your customers on your website. The data such as a customer’s personal details, credit/debit card information, bank details, etc. is secured with SSL. Additionally, having the SSL certificate installed on your website also helps in boosting your website’s ranking in the search engines.

So, the visitors on your website should be accessing it using an SSL-encrypted connection for additional security, accessibility or PCI compliance.

MilesWeb offers SSL certificate with its entire web hosting plans. You can activate this SSL in your Account Management Panel (AMP) under My Account > Manage Free SSL.

You can force visitors to use SSL through your .htaccess file using mod_rewrite.

Forcing HTTPS with .htaccess

1. Redirect All Web Traffic

If you want to force all web traffic to use SSL certificate, run the following code in the .htaccess file in your website’s root folder.

NOTE: If there is an existing code in your .htaccess, add this code above where you will find rules with a similar starting prefix. If there are any issues afterwards, move the new code below some elements – e.g. Options +FollowSymLinks.

2. Redirect Only Specified Domain

In order to force a specific domain for using HTTPS, you can use the below code in the .htaccess file in your website’s root folder:

NOTE: If there is an existing code in your .htaccess, add this code above where you will find rules with a similar starting prefix. If there are any issues afterwards, move the new code below some elements – e.g. Options +FollowSymLinks.

If the above code isn’t working, remove the first two lines and run the code as below:

Ensure that you replace example.com with the domain name for which you are forcing https. Also, you need to replace www.example.com with your actual domain name.

3. Redirect Specified Folder

In case you want to force SSL on a specific folder, input the below code into a .htaccess file that is placed in that particular folder:

NOTE: If there is an existing code in your .htaccess, add this code above where you will find rules with a similar starting prefix. If there are any issues afterwards, move the new code below some elements – e.g. Options +FollowSymLinks.

Ensure that you change the folder reference to the original folder name. Then make sure to replace www.example.com/folderwith your original domain name and folder, you want to force the SSL on.

In this way, you can easily force SSL on any website using the .htaccess.

Avatar
Pallavi is a Digital Marketing Executive at MilesWeb and has an experience of over 4 years in content development. She is interested in writing engaging content on business, technology, web hosting and other topics related to information technology.
Need help? We’re always here for you.