Stop Missing New Laravel Features. Join 1,400+ Devs Getting Alerts. Sign Up Free →

How to Change the Guest Redirection URL in Laravel 12

May 19th, 2025 • 1 minute read time

Starting from Laravel 11, the method of setting the redirection URL for guests changed.

To change the path that guests are redirected to when attempting to access an unauthenticated area, head to bootstrap/app.php.

You'll need to call the redirectGuestsTo method within the withMiddleware callback.

return Application::configure(basePath: dirname(__DIR__))
    //...
    ->withMiddleware(function (Middleware $middleware) {
        $middleware->redirectGuestsTo('/auth/login');
    })
    ->withExceptions(function (Exceptions $exceptions) {
        //
    })->create();

Once you've done that, guests that are attempting to access an area of your application protected by auth middleware will be redirected here.

And as a side note, while it would be convenient to be able to use the route helper here to reference a named route, unfortunately this doesn't work, since helpers and Facades are not loaded at this stage of Laravel's lifecycle.

If you found this article helpful, you'll love our practical screencasts.
Author
Alex Garrett-Smith
Share :

Comments

No comments, yet. Be the first!

Tagged under