简体   繁体   中英

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

您可能会摆脱:

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. If so, and you are using PHP, find the GET variable name and use the following:

$post_number = $_GET["variable_name"];

Then in JavaScript, grab the post number

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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