https跳转

因为PHP和Apache的mod_rewrite跳转设置后都提示无限重定向循环,就用了Javascript来做这件事:

<script type="text/javascript">
var targetProtocol = "https:";
if (window.location.protocol != targetProtocol)
  window.location.href = targetProtocol +
    window.location.href.substring(window.location.protocol.length);
</script>

放在body标签里会在加载页面时立即执行

比如点击https://hiiht.com,就会直接重定向至相应的https页面,如果想https跳转http,targetProtocol的值改成http即可。

Leave a Reply

Your email address will not be published. Required fields are marked *