2011-03-23 126 views
1

我正在使用Javascript和邪惡http-equiv元標記組合將舊博客重定向到一個新博客。爲了防止機器人重複我還補充說:使用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

如何使用重定向到新的網址類似的腳本的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>