JS实现域名跳转的方法 返回状态码200

JS实现域名跳转的方法 返回状态码200

而不是SEO中所需的301重定向,请知悉。

所以使用JS方法的同学请注意

下面附两种JS代码,以供分享。

代码段一:

<script language="javascript">
var thisURL = document.URL.toLowerCase();
var str = "www.";
if(thisURL.indexOf(str)==-1){
var newURL = thisURL.replace("studyonjob.com","www.studyonjob.com");
window.location.href= newURL;
}
</script>

代码段二:

<script language=javascript>
if (document.domain =='studyonjob.com')
this.location = "www.studyonjob.com" + this.location.pathname + this.location.search;
</script>