Link to home
Start Free TrialLog in
Avatar of gingera
gingera

asked on

HTTPS - How to direct http://www.mydomain.com/here.php to https://www.mydomain.com/here.php?

HTTPS SSL PHP HTML Apache Linux

Hello,

How can I redirect people visiting - How to direct http://www.mydomain.com/here.php (NON-SSL) to https://www.mydomain.com/here.php (SSL)?


Thanks.
ASKER CERTIFIED SOLUTION
Avatar of hernst42
hernst42
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gingera
gingera

ASKER

HI hernst,

Because it only affects a few files, I don't really want to change the httpd.conf. .htaccess or PHP check is better.

I tried your codes but it doesn't redirect?

Is there anything wrong with


if (!isset($_SERVER['HTTPS'])) {
   header('Location: https://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF']);
  die(0);
}

Open in new window

Avatar of gingera

ASKER

Hi caterham_www,

RewriteEngine on
RewriteCond %{HTTPS} =off
RewriteRule ^(here\.php)$ https://www.mydomain.com/$1 [R=301,L]

works like a charm! Thanks!
Hm the PHP code works perfect on my server.
Avatar of gingera

ASKER

I tried again. It works! Sorry my fault, I didn't complete the PHP script to test it properly.

THANKS!
Avatar of gingera

ASKER

THANKS for your help!