Redirection from http to https

To ensure that your website is always opened via a secure link, https: // 'protocol, we recommend you to set up redirection from' http: // 'to' https: // '. This way, the browser will automatically redirect the user to the secure protocol (https://your-site.com), even if the user types 'http://your-site.com' in the browser address bar.

To set up redirection, you need to add a few rules to .htaccess as listed below.

The .htaccess file has to be located in the website directory (/public_html/your-site.com). You can also just create one, if it does not exist yet.

Redirection from http: // to https: // for all pages

Redirection of any page from http: // to https: //, including http: // www to https: //

Option 1:
RewriteEngine On
RewriteCond% {SERVER_PORT}! ^ 443 $
RewriteRule. * Https: //% {SERVER_NAME}% {REQUEST_URI} [R = 301, L]

or if you can use Option 2, if Option 1 does not help: Option 2
RewriteEngine On
RewriteCond% {HTTPS} = on
RewriteRule (. *) https: //% {HTTP_HOST}% {REQUEST_URI} [QSA, L]

If the two options are not working and a cyclic redirection occurs:

Option 3

RewriteEngine On
RewriteCond% {HTTPS} off
RewriteCond% {HTTP: X-Forwarded-Proto}! Https
RewriteRule ^ (. *) $ Https: //% {HTTP_HOST }% {REQUEST_URI} [L, R = 301]

Redirection to https from a certain page

Here is how redirection is set up for a sample page named 'login.php'.

Option 1
RewriteEngine On
RewriteCond% {HTTPS} = off
RewriteCond% {REQUEST_URI} = / login.php
RewriteRule (. *) Https: //% {HTTP_HOST}% {REQUEST_URI} [QSA, L]

or Option 2
RewriteEngine On
RewriteCond% {SERVER_PORT}! ^ 443 $
RewriteCond% {REQUEST_URI} = / login.php
RewriteRule. * https: //% {SERVER_NAME}% {REQUEST_URI} [R, L]

Redirection to https for all pages except for one

Here is how redirection is set up for all pages except for a sample page named 'test.php'.

RewriteEngine On
RewriteCond% {HTTPS} = off
RewriteCond% {REQUEST_URI}! ^ / Test.php
RewriteRule (. *) Https: //% {HTTP_HOST}% {REQUEST_URI} [QSA, L]