如何从我的返回网址中获取清晰的网址?

My framework app home url is (/framework/web). I want to get a clear url such as (/framework/web/user/login?next=/framework/web/user/profile) to (/framework/web/user/login?next=/user/profile). In this case i use

//code

 public function getNextURL($url) {
$homeFOLDER = str_replace("/", "_", HomeFOLDER);
$fetchURL = str_replace("/", "_", $url);
$data = str_replace($homeFOLDER, '', $fetchURL);
return $nextURL = str_replace("_", "/", $data);
}

When loaded on my localhost server the code is working properly. But after uploading on my host server it is not working.

It give me [myhostedappserver/user/login?next=userprofile] not [myhostedappserver/user/login?next=/user/profile]. Now in this problem what can i do.

Description: Localhosted php version 7.0.21 hosted server php version 7.0.15