1. Home
  2. Web Hosting
  3. How to Force HTTPS using .htaccess

How to Force HTTPS using .htaccess

Custom site code can cause issues with this method, which can be out of our scope of support.
If the above steps are out of your technical knowledge or ability, we recommend contacting a website developer (outside of us) to assist. 

After installing an SSL certificate, your website is available over HTTP and HTTPS.

Hostko allows all users to configure this setting in just one click, you can also use the .htaccess file to force HTTPS connection.

In this tutorial we will show you how.

Redirect HTTP to HTTPS automatically

One of the many functions you can perform via .htaccess is the 301 redirects, which permanently redirects an old URL to a new one. You can activate the feature to force HTTPS on all incoming traffic by following these steps:

  1. Go to your cPanel > File Manager and open .htaccess inside the public_html folder.
  2. Scroll down to find RewriteEngine On and insert the following lines of code below it:
RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

After making the changes, clear your browser’s cache and try to connect to your site via HTTP. If everything was added correctly, the browser will redirect you to the HTTPS version.

Congratulations! you have successfully edited your .htaccess file and redirected all HTTP traffic to HTTPS, the safe version of your website.

Updated on December 3, 2020

Was this article helpful?

Related Articles

Need Support?
Can't find the answer you're looking for?
Contact Support