Casbay Knowledge Base

Search our articles or browse by category below

Redirect all traffic to HTTPS using an .htaccess file.

Last modified: April 15, 2021
You are here:
Estimated reading time: 1 min

Redirect all traffic to HTTPS using an .htaccess file

What is SSL?

Secure Sockets Layer or SSL is a standard security protocol to establish encrypted links and communication between a web server and a browser.

SSL is commonly used to ensure that all data transmitted between the web server and browser remains encrypted.

An SSL certificate is necessary to create SSL connection. You would need to give all details about the identity of your website and your company as and when you choose to activate SSL on your web server.

In order to force your web traffic to use HTTPS, you need to edit the codes in the .htaccess file.

Before we move onto redirecting HTTP to HTTPS, click HERE to find out how you can edit .htaccess file. If you already know, you can proceed with this guide.

1. Redirect All Web Traffic

If you have existing code in your .htaccess, add the following:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$$1 [R,L]

2. Redirect Only a Specific Domain

To redirect a specific domain to use HTTPS, add the following:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$$1 [R,L]

3. Redirect Only a Specific Folder

To redirect HTTPS on a specific folder, add the following:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} folder
RewriteRule ^(.*)$$1 [R,L]

Note: Replace “example” with your actual domain name wherever required. Also, in case of the folder, replace /folder with the actual folder name.

We hope this article helped you to learn How to redirect traffic to HTTPS using .htaccess file. For more articles, please go to Knowledge Base.

Was this article helpful?
Dislike 0
Views: 3