Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel: Catch all routes that does not have /api/ segment

Tags:

regex

laravel

I need to catch all routes, except those that have /api/ segment in them. I know how to catch every single route

Route::any('{all}', 'AngularController@serveFrontend')->where('all', '(.*)');

But what do I need to change so that my api routes aren't captured by this string ?

like image 870
user991 Avatar asked May 31 '16 10:05

user991


1 Answers

You can catch all routes where the path does not start with api

Route::any('{all}', 'AngularController@serveFrontend')->where('all', '^(?!api).*$');

Or simply leave your catchall as the last route and it'll work as expected.

like image 109
Ben Swinburne Avatar answered Sep 20 '22 13:09

Ben Swinburne