LPS-43142 making the fix more robust by checking for portalURL before re...

...turning the substring