问题
I'm working with a Library for my university's authentication system (Ucam_Webauth) which means I have to redirect to the authentication server in one of the methods. Unfortunately, I cannot return a Redirect:to() because of the architecture of this library. The library itself uses header('Location: ...'); but this isn't working for some reason.
If I make the programme die(); after sending the header it works, but otherwise it doesn't.
Any idea how I can fix this?
回答1:
return redirect()->to('url')->send();
Sends HTTP headers and content. In my application, send() method acts like 'exit()' and is testable
回答2:
I'm not sure I follow. Laravel sets the Location header as part of the Redirect::to() method. If you want to more explicitly define the response you could do it like this.
return Response::make( '', 302 )->header( 'Location', $url );
If that doesn't work I'd probably just fall back on the php stdlib header() and return null.
If all of this still doesn't do any good, maybe the profiler is messing things up. If it is turned on, try disabling it in the config.
回答3:
exit; after header to stop further code execution.
<?php
header('Location: http://www.example.com/');
exit;
回答4:
try
return Redirect::to('url');
回答5:
For example, For this route:
Route::get('hello', array('as' => 'hello_name', 'uses' => 'HelloController@getHello'));
In laravel, you can redirect to url simply using
return Redirect::to('hello');
Alternatively, you can redirect to named route simply using
return Redirect::route('hello_name');
来源:https://stackoverflow.com/questions/15643718/location-headers-in-laravel