How to Redirect users automatically from old portal to new portal

Prasad43
Tera Guru

Hello folks,

We have few portals which we are not using. So I made Default to false.

But still users are able to access those portals using urls.

I want to redirect users to our new portal(specific url) when they are accessing old portals.

Can some one please assist on this.

Thanks

Prasad K

1 ACCEPTED SOLUTION

Oleg
Mega Sage

You can replace Theme of old portals. Theme allows to include JS Includes, which will be loaded on attempt to display of every URL of old portals. Thus, you can create UI Script, which makes redirection to new portal, and load it as part of "Redirection Theme", which you assign to all old portals. The code of UI script can look as following:

(function () {
    var loc = window.location;
    //var oldUrl = loc.protocol + "//" + loc.host + loc.pathname + loc.search + loc.hash;
    var newUrl = loc.protocol + "//" + loc.host + "/newPortal" + newSearch + loc.hash;
    window.location.replace(newUrl);
})();

The method location.replace allows to redirect to new URL in very clean way. The current page will not be saved in session History, meaning the user won't be able to use the back button to navigate to it. As the result users will be able to use old links (for example links from old emails) and access to new URLs instead of old one. You can make the above code more complex and implement more complex algorithm of replacing of old URL to new one.

View solution in original post

6 REPLIES 6

Oleg
Mega Sage

You can replace Theme of old portals. Theme allows to include JS Includes, which will be loaded on attempt to display of every URL of old portals. Thus, you can create UI Script, which makes redirection to new portal, and load it as part of "Redirection Theme", which you assign to all old portals. The code of UI script can look as following:

(function () {
    var loc = window.location;
    //var oldUrl = loc.protocol + "//" + loc.host + loc.pathname + loc.search + loc.hash;
    var newUrl = loc.protocol + "//" + loc.host + "/newPortal" + newSearch + loc.hash;
    window.location.replace(newUrl);
})();

The method location.replace allows to redirect to new URL in very clean way. The current page will not be saved in session History, meaning the user won't be able to use the back button to navigate to it. As the result users will be able to use old links (for example links from old emails) and access to new URLs instead of old one. You can make the above code more complex and implement more complex algorithm of replacing of old URL to new one.

For any other newbs like me, I had to change one thing in the above script for it to work exactly how I needed it.  Here's my final code below:

 

(function () {
    var loc = window.location;
    //var oldUrl = loc.protocol + "//" + loc.host + loc.pathname + loc.search + loc.hash;
    var newUrl = loc.protocol + "//" + loc.host + "/sp" + loc.search + loc.hash;
    window.location.replace(newUrl);
})();

The key change was replacing newSearch with loc.search.

Great explanation, thanks so much for the help!

Akhil42
Tera Contributor

Hi @Oleg ,

 

I want this particular scenario only when users clicks on Notification Links(URI_REF).