Your Gateway To Digital Success
Wesbytes Blue Logo

Wesbytes Knowledge Base

Search our articles or browse by category below

Redirect All Traffic to HTTPS using an .htaccess File

Last modified: July 2, 2022
You are here:
Estimated reading time: 1 min

What is SSL?

An industry-standard security protocol called Secure Sockets Layer, or SSL, is used to create secure connections and communications between a web server and a browser.

To guarantee that all information passed between the web server and browser is encrypted, SSL is frequently utilised.

To establish an SSL connection, you need an SSL certificate. As soon as you decide to enable SSL on your web server, you will need to provide all information on the identity of your website and your business.

You must modify the codes in the.htaccess file to force HTTPS for all of your online traffic.

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.

Was this article helpful?
Dislike 0
Views: 4