简体   繁体   English

使用Javascript和http-equiv重定向

[英]Redirects with Javascript and http-equiv

I am redirecting an old blog to a new one with a combination of Javascript and evil http-equiv meta tag. 我正在将一个旧的博客重定向到一个结合了Javascript和邪恶的http-equiv元标记的新博客。 In order to prevent duplication in robots I have also added: 为了防止机器人重复,我还添加了:

<meta name="robots" content="noindex" />

The redirect snippets are as below: 重定向代码段如下:

<!--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/" />

This however redirects deep-links to the front page of the new_loc which can be disorienting for the incoming reader. 但是,这会将深度链接重定向到new_loc的首页,这可能会使传入的阅读器迷失方向。 I would like the relative link to remain unchanged for both the javascript and http-equiv tricks. 我希望javascript和http-equiv技巧的相对链接保持不变。 What would be the best way to achieve this ? 实现此目标的最佳方法是什么?

how about similar script for redirect to new url using javascript: 使用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>

or even Short CUT: 甚至是短切:

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM