虚拟主机不像独立服务器,可以远程进入系统操作,虚拟主机只是简单的控制面板,所以很多东西不能操作,还是要靠网页来执行
这是http跳转到https,无www跳转到www的代码,纯小白记录
.htaccess文件(适用Linux系统,Apache Web服务器)
RewriteEngine On RewriteCond %{HTTP_HOST} ^you6tv.com [NC] RewriteRule ^(.*)$ https://www.you6tv.com/$1 [L,R=301] RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.you6tv.com/$1 [L,R=301]
php代码(适用windows服务器)
<?php //http转化为https if ($_SERVER["HTTPS"]<>"on") { $xredir="https://".$_SERVER["SERVER_NAME"]. $_SERVER["REQUEST_URI"]; header("Location: ".$xredir); } ?> <?php <?php $the_host = $_SERVER['HTTP_HOST'];//取得当前域名 $the_url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';//判断地址后面部分 $the_url = strtolower($the_url);//将英文字母转成小写 if($the_url=="/index.php")//判断是不是首页 { $the_url="";//如果是首页,赋值为空 } if($the_host == 'you6tv.com')//如果域名是不带www的网址那么进行下面的301跳转 { header('HTTP/1.1 301 Moved Permanently');//发出301头部 header('Location:http://www.you6tv.com'.$the_url);//跳转到带www的网址 } ?>
已有 991 位网友参与,快来吐槽:
发表评论