Using Apache .htaccess to force redirection of web site pages (http://) to the secure site (https://)

For those whose web sites are not hosted on one of our Plesk servers, here is a way to force redirect the unsecure http:// to secure connection (https://) with Apache .htaccess.

It can be accomplished by creating a file named .htaccess (The name starts with a dot) containing these lines:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

The .htaccess file should be uploaded in the web site main folder.

In case you wish to force HTTPS only for a particular folder you can use:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} securefolder
RewriteRule ^(.*)$ https://www.domain.com/somefolder/$1 [R,L]

The .htaccess file should be uploaded in the folder where you need to force HTTPS.

On web sites hosted on one of our Plesk shared servers or VPS, you can do that from the domain subscription's Plesk Panel.


Properties ID: 000220   Views: 5868   Updated: 3 years ago