js 实现 http 强制重定向至 https


js 实现 http 强制重定向至 https

 

var reg = /^(192.168.1.)/;
    if(window.location.hostname !== 'localhost' && !reg.test(window.location.hostname)) {
      // 判断非本地server时 http强制转换成https
      var targetProtocol = "https:";
      if (window.location.protocol != targetProtocol)
      window.location.href = targetProtocol +
      window.location.href.substring(window.location.protocol.length);
    }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM