$current_path = $this->request->getCurrentRequest()->headers->get('referer'); $path = explode('8000', $current_path); //8000 is just a part of a string, from where we are breaking the string. $route_name = Url::fromUserInput($path[1])->getRouteName(); return $this->redirect($route_name, ['user' => $user->id()]);