JS重定向代码
<script language="javascript">
if (document.domain =="kangqiao.org")
this.location = "http://www.kangqiao.org" + this.location.pathname + this.location.search;
</script>
多个域名跳转到指定域名
<script>
if (document.domain =="a.kangqiao.org" || document.domain =="b.kangqiao.org" || document.domain =="c.kangqiao.org")
this.location = "http://www.kangqiao.org" + this.location.pathname + this.location.search;
</script>
(会将多个域名的http和https跳转到http://www.kangqiao.org)
优化版:多个域名跳转到指定域名
<script>
if (document.domain !="kangqiao.org")
this.location = "http://www.kangqiao.org" + this.location.pathname + this.location.search;
</script>
(访问当前页面只要域名不是kangqiao.org都会自动跳转到http://www.kangqiao.org)
http强制js跳转到https
<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>
评论