PDA

View Full Version : HTTPS Re-Direct for PHP


bswinnerton
27th March 2008, 17:39
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?

daveb
27th March 2008, 17:55
You could use this in your apache directives for the site or in your .htaccess.
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

bswinnerton
27th March 2008, 18:46
Hey that worked great!!!

Thanks

sjau
31st March 2008, 11:24
or a simple php script as index.php:


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

bswinnerton
31st March 2008, 14:54
I'm pretty sure that would create an infinite loop because there is nothing telling it to stop if it is already on https.

sjau
31st March 2008, 14:56
Only if you have the same index for the https and http version ;)