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

Dhananjay Pawar
Kilo Sage

Hello Prasadk

Please check below link it will help you.

https://community.servicenow.com/community?id=community_blog&sys_id=cbcda2e9dbd0dbc01dcaf3231f961949

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks.

Dhananjay.

Aniko Hegedus
Tera Expert

This is a nice solution, I would just like to warn all of you that if at the UI script you select UI type - desktop and global - all, then you are in trouble, because no matter where you go, all pages will be redirected to the new location and you will not be able to deactivate it again!! 
Don't ask me how I know ðŸ˜£
Finally I figured that if you open the developer tool -> cogwheel (aka settings) and then you disable javascript then some pages will not redirect you. Mostly pages that don't load the general theme, the ones without the header. Once you are there, you can somehow navigate back to the UI script. Since javascript is disabled, you will not be able to delete or deactivate it.
But you can open the background script (sys.scripts.do) and from there with the sys_id of the UI script you can deactivate it and give an other try to the redirection. ðŸ˜„