How to force HTTPS using the htaccess file

Applies to:
Professional Hosting
Business Hosting
Reseller Hosting

Difficulty:
Easy

Time Needed:
10 minutes

Introduction

This is a quick step-by-step walkthrough for forcing your site to load via HTTPS, instead of HTTP.

We recommend all websites relying on SSL encryption take these steps to guarantee your website traffic is using an encrypted connection.



How to force HTTPS using the .htaccess file

Step 1

Locate your .htacess file

Firstly, you need to locate your .htaccess file using your prefered FTP client. This will be in your /httpdocs folder.

When you have found the .htaccess file, you'll need to download it to your local machine and open it in your favourite code editor.

Locate your .htacess file

Step 2

Force all traffic to use HTTPS

To force all traffic on your domain to use HTTPS, simply add the following. If you have existing code in your .htaccess file, you should add this above your current rewrite rules.

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

Please note: You should substitute 'yourdomain.com' with your own domain name.

Force all traffic to use HTTPS

Step 3

Force all traffic on specific pages to use HTTPS

If you want to force HTTPS on specific pages or sections of your website, update the above code to the following.

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

Please note: You should substitute 'yourdomain.com' with your own domain name, and 'folder' with the path of your choice.

Force all traffic on specific pages to use HTTPS

Step 4

Upload your updated .htaccess file

Once you have updated your .htaccess file, you need to upload it back into your /httpdocs folder.

Please note: We strongly recommend making a backup copy of your exsisting .htaccess file before overwriting it.

Upload your updated .htaccess file

Was this helpful?

   
2 people found this article helpful