Redirect to a custom 404 page in Laravel (and why not to redirect to the homepage)

Laravel Questions editorial team
Editorial team · 19 October 2026

This question was asked for Laravel 5.4, where you overrode render($request, Exception $e) in app/Exceptions/Handler.php. That code no longer fits current Laravel, and the redirect it did is not a good idea anyway. Here is the current way.

Best: a custom 404 view, no handler code

Create resources/views/errors/404.blade.php:

<h1>Sorry, we could not find that page</h1>
<p><a href="{{ url('/') }}">Back to the homepage</a></p>

Laravel shows it for every missing URL and every abort(404), and the response keeps the 404 status. Search engines understand that the page does not exist.

Why not redirect to /

The old code returned response(redirect(url('/')), 404). A redirect sends status 302 to the homepage, and search engines treat many of these as soft 404s. Visitors also lose the URL they asked for. Redirect only for URLs you know moved, with a 301.

If you still want a callback

Register a render callback for NotFoundHttpException. On Laravel 10.x it goes in Handler::register():

use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

public function register(): void
{
    $this->renderable(function (NotFoundHttpException $e, $request) {
        return redirect('/');
    });
}

Newer skeletons configure the same thing in bootstrap/app.php through ->withExceptions(...). That form has not been run for this answer.

Tested on Laravel 10.x (PHP 8.1) and 12.x (PHP 8.3): the tests check that a missing URL and abort(404) return 404 with the custom view, and that a render callback redirect returns 302. Source: tests/laravel-verification/files/q999.

Our network