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;
DigitalOcean Referral Badge
最后修改:2024 年 03 月 23 日
如果觉得我的文章对你有用,请随意赞赏