Actually, I just found an answer on stackoverflow.
I needed to do:
redirect()->to($external_uri)->send();
This worked.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi All,
I am new to Laravel so I might be missing something really simple. I cannot seem to get redirect to work in a controller to send user to an external website.
For example, in a controller I have a function:
public function goToGoogle() { $external_uri = 'https://www.google.com'; return redirect($external_uri); }
This gives me a blank page when goToGoogle() function runs (stays on the local route URI that initiated the controller function).
While, below works in the web.php routes page: Route::get('/test', function() { return redirect('https://www.google.com');});
if I go to localhost/test, it redirects me to https://www.google.com.
I am not sure what I am missing. Thank you in advance for any advice/feedback you might have.
John
@jlin1010 You need to use away to redirect to external URLs.
return redirect()->away('https://www.google.com');
https://laravel.com/docs/6.x/responses#redirecting-external-domains
Please or to participate in this conversation.