更改博客域名后,在搜索中很多来自原始地址的人只能跳至首页。 虽然可以在站内搜索中发现什么,但这是糟糕的用户体验。 由于只更改了域名而没有更改其他伪静态,因此我们找到了一种方法,用javascript替换当前站点中的域名,用当前lms.im替换原始www.happyet.org,然后自动跳转。
代码入:
current _ URL=window.location.href;
函数替换全部(str 1、str2、str3) )/str1是父字符串,str2是替换。 str3已替换为
var k
vartmp=str1.split(str2) ) )
k=tmp[0]
for(I=1; itmp.length; I ) {
k=str3 tmp[i]
}
返回k
}
target _ URL=替换全部(current _ URL,' www.happyet.org ',' lms.im ' );
window.location=target_url;
在上面的代码中,可以将http://www.happy et.org/oooxxxx/Gaga.html自动变为http://lms.im/ooooxxxx/gaga.html。 只能做这个。
这个代码放在服务器传说的第404页内。 例如,我的da主机在根目录下有404.shtml。 做那个就好了。
当前,此代码中有一个错误。 地址是index.php吗? 这种情况下好像会发生错误,没关系。 最后,您可以跳转到新域名的首页。 另外,我的博客地址都是假静态的,没有这个问题。
评论有很好的方法,但我没有尝试过。 只要replace函数可以这样使用,那就应该没错。 我什么业余也不查。 从旧的域名301到新的域名。
var current _ URL=window.location.href;
target _ URL=current _ URL.replace (' www.happy et.org ',' lms.im ' );
window.location=target_url;