Warning: call_user_func_array() expects parameter 1 to be a valid callback, class 'BaiduLinkSeo_Plugin' does not have a method 'post' in /www/wwwroot/www.5alen.com/var/Typecho/Plugin.php on line 489
php让http跳转https - 小果冻博客

php让http跳转https

技术文章 https ssl 301跳转 2019-03-24 阅读:107

很多人使用了ssl后,发现httphttps都可以打开,但是不想让用户使用http协议,在服务器iisnginx 或 apache 想尽办法,各种伪静态,各种301的跳转,最终发现还是有缺陷,那么下面教大家一句php来实现

方法一:https状态

if(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off'){
    Header("HTTP/1.1 301 Moved Permanently");
    header('Location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
}

方法二:判断端口

if($_SERVER['SERVER_PORT']=="80"){
   Header("HTTP/1.1 301 Moved Permanently");
   header('Location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
}

0条评论

0:00