Setting https redirect using .htaccess

If you are using an SSL certificate with your domain, you may need to set up a redirect when someone trying to access the domain with HTTP to load it with HTTPS automatically.  We can use the following redirections as per your needs:

1. If you need to redirect all HTTP requests to HTTPS, paste the following in the .htaccess configuration:

RewriteEngine On 

RewriteCond %{SERVER_PORT} 80 

RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

2. If you need to force SSL on a specific folder inside the home directory you can insert the following code into a .htaccess file placed in that specific folder:

RewriteEngine On 

RewriteCond %{SERVER_PORT} 80 

RewriteCond %{REQUEST_URI} folder 

RewriteRule ^(.*)$ https://www.example.com/folder/$1 [R,L]

*Please replace the domain 'example.com' with the actual domain name.

  • htaccess redirect to https
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How To Install and Use Docker on Ubuntu 16.04

Introduction Docker is an application that makes it simple and easy to run application processes...

Change Main IP of the server :: Vesta Panel

If we are changing the main IP of a server installed with Vesta panel, we can use the following...

cPanel: Apache-FastCGI Data Timeout Error

If you are using a cPanel server and have FastCGI enabled in Apache, you might be facing the...

Domainkey installer in cPanel

You can use the following cPanel script to install domainkey for an account...

Email issues :: Common Troubleshooting Steps

Here I will discuss some common errors and their solution: We are using a mail relay setup for...