中国站
帮助中心 > 安全 > SSL安全证书 > 证书安装 > 使用程序强制跳转到HTTPS

使用程序强制跳转到HTTPS

兼容

  1. <!-- 如果检测到是http页面,则自动跳转到对应的https页面 -->
  2. <script type="text/javascript">
  3. if (document.location.protocol != "https:") {
  4. location.href = location.href.replace(/^http:/,"https:");
  5. }
  6. </script>

ASP

  1. <%
  2. If Request.ServerVariables("SERVER_PORT")=80 Then
  3. Dim strSecureURL
  4. strSecureURL = "https://"
  5. strSecureURL = strSecureURL & Request.ServerVariables("SERVER_NAME")
  6. strSecureURL = strSecureURL & Request.ServerVariables("URL")
  7. Response.Redirect strSecureURL
  8. End If
  9. %>

PHP

  1. if(!isset($_SERVER['HTTPS'])||!$_SERVER['HTTPS']){
  2. $url ='https://'. $_SERVER['HTTP_HOST']. $_SERVER['REQUEST_URI'];
  3. header('Location: '. $url);exit;
  4. }