Redirect every request in a Laravel app original
I recently had to redirect every single request in a Laravel app. You might think that would be as easy as this:
Route::get('/', function() {
return redirect('https://targetdomain.com');
});
But that'll only redirect the "/" page. All other requests will return a 404. Here's how redirect every single request:
Route::get('{any}', function() {
return redirect('https://targetdomain.com');
})->where('any', '.*');
If you need to redirect all pages except "/", you can do this:
Route::get('{anyExceptRoot}', function() {
return redirect('https://targetdomain.com');
})->where('anyExceptRoot', '[^/]*');