简体   繁体   中英

Force https on index.php

I'm running apache and I would like to force https only on the root page (www.domain.com) which is index.php. Any other pages I would like to leave up to the user. Any suggestions?

You can do something like this:

if ($_SERVER['HTTPS'] == false)
  header("Location: https://www.domain.com/");

Or, a better way:

$ssl = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? true:false;
if (!$ssl)
  header("Location: https://www.domain.com/");

This is a little PHP hack. It can be done in a better way using .htaccess .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM