HTTPS Re-Direct for PHP

Discussion in 'Programming/Scripts' started by bswinnerton, Mar 27, 2008.

  1. bswinnerton

    bswinnerton New Member

    Hey everybody, I'm trying to make a HTTPS redirect for my webmail so that whenever a user goes to http://www.mydomain.com/mail it is automatically redirected to https://www.mydomain.com/mail.

    Everything that I have tried so far causes an infinite loop. Does anyone have any good code for this?
     
  2. daveb

    daveb Member

    You could use this in your apache directives for the site or in your .htaccess.
    Code:
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
     
  3. bswinnerton

    bswinnerton New Member

    Hey that worked great!!!

    Thanks
     
  4. sjau

    sjau Local Meanie Moderator

    or a simple php script as index.php:

    Code:
    <?php
    header('Location: http://www.example.com/');
    ?>
    
     
  5. bswinnerton

    bswinnerton New Member

    I'm pretty sure that would create an infinite loop because there is nothing telling it to stop if it is already on https.
     
  6. sjau

    sjau Local Meanie Moderator

    Only if you have the same index for the https and http version ;)
     

Share This Page