HTTP强制跳转HTTPS的几种方法!

低调G
2021-06-04 / 0 评论 / 507 阅读 / 正在检测是否收录...

javascript脚本

<script type="text/javascript">
 if (location.protocol == 'http:') {  //  强制转换当前地址为HTTPS
   location.protocol = 'https'
 }
</script>

PHP脚本

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

Apache服务器.htaccess文件

RewriteEngine on
RewriteBase /yourfolder
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

Nginx服务器

rewrite ^(.*)$  https://$host$1 permanent;
0

评论 (0)

取消