简体   繁体   中英

Redirect a urls domain but not it's ending (ending meaning /index.html)

I'll show you what i mean. So let's say i had the url www.url1.com and I changed the domain to www.url2.com but there are links to my website on a ton of other sites that still go to url1.com/post/12345678 and url1.com/post/91029323, etc. I still own both domains, but i need url1.com/post/1 and url1.com/post/9 to redirect to url* 2 *.com/post/1 and url* 2 *.com/post/9 instead.

Do you get what I'm saying?

Now these aren't really websites these are blogs hosted by tumblr but same difference. I think I have the code figured out, but it just doesn't seem to work.

<html>
    <head>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script language="javascript" type="text/javascript">
       function myFunction()
        {
        var permalink = document.URL;
        var newlink = permalink.replace("url1","url2");
        window.location.replace(newlink);
        }
    </script>
</head>
    <body onload="myFunction()">
        come ooon redirect already
    </body>
</html>

For some reason it works in the previews while editing the blogs theme (its an iframe next to the html code(tumblr thing)), but not on the blog itself.

And if there is a way easier way to do it (please javascript jquery only (unless it's html or css (probably not css)) everything else never works for me) please tell me i'm oblivious sometimes Thank's ahead of time.

采用

window.location = newlink;

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