redirect HTTP to HTTPS

Why you should use HTTPS?

Browsers show unstable alerts related to SSL. Your website will appear insecure to visitors if SSL is not installed. As a result, using an SSL-encrypted link is required to solve this problem. It is good for security.

What is SSL?

SSL stands for Secure Sockets Layer. It is a security protocol for establishing encrypted links between a web server and a browser.

All data transmitted between the web server and the browser is encrypted thanks to SSL technology.

How to use HTTPS by editing the .htaccess file?

Edit the codes in the .htaccess file to redirect your web traffic to use HTTPS.

The .htaccess file contains instructions and directives that tell the web server how to behave in specific situations.

Redirecting HTTP to HTTPS

Redirecting all pages and posts

If you want to redirect all the traffic to HTTPS then you can add the following code to .htaccess file.

Replace ‘’ with your own domain name.

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

alternatively you can add the following code to redirect a specific domain. this will accept the HTTP scheme and redirect to HTTPS.

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

The abpve code contains the following part.


Do not remove the slash and the period. It is part of the regular expression syntax. Just replace ‘yourdomain’ with your domain name and ‘.com’ with .net, .info, etc.

Redirect Only a Specific folder in .htaccess file

There is option to redirect only a specified folder. If you want to do this with a particular folder then try this code.

Copy and paste this code in your .htaccess file.

Replace ‘folderName’ with the real folder name in the following code.

Replace ‘yourdomain’ with your real domain name.

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

we are assuming that you are familar with the basic editing skills to the .htaccess file. However we are not responsible for any misuse or improper usage of above codes.

Leave a Reply

Your email address will not be published. Required fields are marked *