简体   繁体   English

使用 Laravel 重定向到外部 URL(跨域)

[英]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示例 $_SERVER['REQUEST_URI'] 是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_url);

Redirect::to does not work as it appends base_url and then the redirect_to_url string. Redirect::to 不起作用,因为它附加了 base_url 和 redirect_to_url 字符串。

How to achieve this using Laravel 5.4 with redirect_to_url to be taken from REQUEST_URI?如何使用 Laravel 5.4 和从 REQUEST_URI 获取的 redirect_to_url 来实现这一点?

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

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

If it is the Redirect URL from the above mentioned URL you want.如果它是您想要的上述 URL 的Redirect URL Then you can get it from the Request Object然后就可以从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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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