我将旧博客重定向到一个新的博客,其中包含Javascript和邪恶的http-equiv元标记。为了防止机器人重复,我还添加了:
<meta name="robots" content="noindex" />
重定向代码段如下:
<!--Execute javascript rediect-->
<script type="text/javascript"><!--//--><![CDATA[//><!--
var url = "http://new_loc.blogspot.com/"
(document.images) ? location.replace(url) : location.href = url;
//--><!]]>
</script>
<!--If the browser can be bothered to refresh with new content,
also works if browser has javascript disabled, in mozilla family -->
<meta http-equiv="refresh" content="0;URL=http://new_loc.blogspot.com/" />
然而,这会将深层链接重定向到new_loc的首页,这可能会使传入的阅读器迷失方向。我希望javascript和http-equiv技巧的相对链接保持不变。实现这一目标的最佳方法是什么?
答案 0 :(得分:0)
如何使用javascript重定向到新网址的类似脚本:
<script>
var myUrl = location.href;
var old = /http:\/\/old_loc.blogspot.com/gi;
var new1='http://new_loc.blogspot.com';
myNewUrl = myUrl.replace(old, new1);
window.location = myNewUrl;
</script>
甚至短切:
<script>
var old = /http:\/\/old_loc.blogspot.com/gi;
var new1='http://new_loc.blogspot.com';
window.location = window.location.href.replace(old, new1);
</script>