How do I make a Catch-All Route in Laravel

You could also catch ‘all’ by using a regex on the parameter.

Route::group(['prefix' => 'premium-section'], function () {
    // other routes
    ...
    Route::get('{any}', function ($any) {
        ...
    })->where('any', '.*');
});

Also can catch the whole group if no routes are defined with an optional param.

Route::get('{any?}', function ($any = null) {
    ...
})->where('any', '.*');

This last one would catch example.com/premium-section as well.

Leave a Comment