简体   繁体   English

JavaScript相对页面重定向?

[英]JavaScript relative page redirecting?

So, I want to change my tumblr url and redirect everyone from my old one to the new one, but I want them to be redirected to the post they were linked to, for example /post/64948618646. 因此,我想更改我的tumblr网址,并将每个人都从旧的重定向到新的, 我希望将它们重定向到与之链接的帖子,例如/ post / 64948618646。 I'm quite fond of this code: 我非常喜欢以下代码:

<script type="text/javascript">
<!--
   window.location="http://someurl.tumblr.com";
//-->
</script>

so is it possible to somehow get this like http://oldurl.tumblr.com/post/64948618646 redirect not only to http://newurl.tumblr.com but also http://newurl.tumblr.com/post/64948618646 ? 所以有可能以某种方式使它像http://oldurl.tumblr.com/post/64948618646不仅重定向到http://newurl.tumblr.com,而且重定向到http://newurl.tumblr.com/post/64948618646

您可能会摆脱:

window.location.href = "http://new-url.com" + window.location.pathname;

I am not too familiar with Tumbler, but I am going to assume the last number in the URL you provided is a GET value. 我对Tumbler不太熟悉,但是我将假设您提供的URL中的最后一个数字是GET值。 If so, and you are using PHP, find the GET variable name and use the following: 如果是这样,并且您正在使用PHP,请找到GET变量名称并使用以下命令:

$post_number = $_GET["variable_name"];

Then in JavaScript, grab the post number 然后在JavaScript中获取帖子编号

var post_number = <?php echo $post_number; ?>;
var url = "http://someurl.tumblr.com/post/" + post_number;
window.location = url;

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

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