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)