PHP http链接转https链接(解决老http二维码在微信不能强制转https问题)

以thinkphp5为例

在index.php中加入

// 检查是否为HTTPS请求
if (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] !== 'on') {
  // 非HTTPS请求,重定向到HTTPS
  $redirect = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  header('HTTP/1.1 301 Moved Permanently');
  header('Location: ' . $redirect);
  exit();
}

 

posted @ 2024-10-26 10:59  zhang_you_wu  阅读(85)  评论(0)    收藏  举报