多变php服务中心

当前位置: 首页>站长学院>模板插件> ecshop部署https(ssl)后设置301跳转将http跳转到https

ecshop部署https(ssl)后设置301跳转将http跳转到https

来源:多变php服务中心 发布时间:2018-07-25关注度:992 ℃
ecshop部署https(ssl)后设置301跳转将http跳转到https

怎么设置http跳转到https?在为网站部署SSL证书后,可以实现https加密访问,但是网站的用户往往习惯了http访问,这个时候我们就需要设置访问http时自动跳转到https


ecshop程序级跳转方法(多变php服务中心就是采用这种方案实现的

打开includes/init.php

查找

/* 取得当前ecshop所在的根目录 */

define('ROOT_PATH', str_replace('includes/init.php', '', str_replace('\\', '/', __FILE__)));

 给其上方添加 

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

php常用解决方法

if ($_SERVER["HTTPS"] <> "on")
{
    $xredir="https://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];  header("Location: ".$xredir);


JS常用解决方法 

<script type="text/javascript">
var url = window.location.href;
if (url.indexOf("https") < 0)
{
    url = url.replace("http:", "https:");      
window.location.replace(url);
}
</script> 


还有一种方法就是根据服务器环境来实现301跳转,多变php服务中心将专门依文章的形式为大家展示!

本文地址:https://www.phpicu.com/article.php?id=40

    责任编辑:多变php服务中心

    相关阅读