Redirect http -> https
Posted by Staff Team, Last modified by Andy Williams on 04 March 2007 10:34 PM

How would it be possible to get my users from http:// to an https:// connection?

There are a couple of ways, one involves PHP and the other .htaccess. There is no real difference, so please use whichever one you feel most comfortable with.

To do this in .htaccess you can do the following:

RewriteEngine on
#Options +FollowSymlinks
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^(.*) https://yourdomain.com/$1 [R,L]

* Please ensure that you save this file in your /public_html/ folder.

 

Below is how you can do the same in PHP:

<?php

if (!$_SERVER['HTTPS'])

{

 header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . $_SERVER['QUERY_STRING']);

 exit;

}

?>

* Please note if you are using PHP to re-direct these users, please note that you will have to save the above code as: index.php and it would go in the directory where the file that you want to change from http:// to https://

In addition, please remember that you can always copy the above code and put it into your own index.php to create the same effect.

(301 vote(s))
Helpful
Not helpful

Comments (0)
Post a new comment
 
 
Full Name:
Email:
Comments:
CAPTCHA Verification 
 
Please enter the text you see in the image into the textbox below (we use this to prevent automated submissions).