Apr 14, 2021
5
Level 4
Redirect on a 404
Hi.
I'm looking to redirect users if they 404 on my site. I'm aware that I can make a custom page, but this is not what I want. I want to redirect them to my home page.
Level 2
https://laravel.com/docs/8.x/routing#fallback-routes
Fallback Routes
Using the Route::fallback method, you may define a route that will be executed when no other route matches the incoming request. Typically, unhandled requests will automatically render a "404" page via your application's exception handler. However, since you would typically define the fallback route within your routes/web.php file, all middleware in the web middleware group will apply to the route. You are free to add additional middleware to this route as needed:
Route::fallback(function () {
//
});
The fallback route should always be the last route registered by your application.
Route::fallback(function () {
return redirect('/');
});
5 likes
Please or to participate in this conversation.