简体   繁体   中英

Redirect to external URL (cross domain) with Laravel

Sample $_SERVER['REQUEST_URI'] is http://asdf.com/redirect/jhdsjkas/userDetails?redirect_back_url=http://userInfo.com/result?pass

$uri_string = explode("?", $_SERVER['REQUEST_URI']);
if(count($uri_string) > 1){
    $url_info = explode("&", $uri_string[1]);
    $base_url_string = explode("=", $url_info[0]);
    $redirect_to_url = $base_url_string[1].'result?pass';
}else{
    $redirect_to_url = '';
}

return Redirect::to($redirect_to_url);

Redirect::to does not work as it appends base_url and then the redirect_to_url string.

How to achieve this using Laravel 5.4 with redirect_to_url to be taken from REQUEST_URI?

您可以从 URI 参数中获取值并使用以下方法重定向:

return Redirect::away(request('redirect_back_url'));

If it is the Redirect URL from the above mentioned URL you want. Then you can get it from the Request Object

/** Request $request  <---> it is normally passed as parameter in routed functions **/

if($request->has('redirect_back_url')){
    // response()->redirect($request->get('redirect_back_url')); **
    Redirect::away($request->get('redirect_back_url'));
}else{
    // return some error
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM