Setting https redirect using .htaccess Print

  • htaccess redirect to https
  • 0

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.


Was this answer helpful?

« Back