0

Yesterday I had asked how to make sure my wildcard route does not match any of the Laravel Nova routes and found the solution quickly.

Nova routes are now ignored as I wanted. But this also seems to throw off the matching in some other way. Here is the defined route:

Route::get('/{seite}/{zweit?}/{dritt?}', 'PagesController@anyPage')
    ->where('seite', '^(?!nova).*$');

/blog -> should match and does match

/blog/news -> should match but does not and leads to a 404

/blog/news/post-123 -> same as above

If I remove the regex from the route definition, all of these examples are matched, but then of course I cannot access Nova anymore.

Any idea what could be causing this?

asto
  • 197
  • 2
  • 17

1 Answers1

0

It's likely because the RegEx is catching the / character in the uri. So /blog/news is captured by the seite parameter. It would be interesting to see your PagesController and full routes.php, if you can share.

Tomy Smith
  • 175
  • 8
  • This is the entire route file: Route::get('/', 'PagesController@frontPage'); Route::get('/en/', 'PagesController@frontPageEnglish'); Route::get('/{seite}/{zweit?}/{dritt?}', 'PagesController@anyPage') ->where('seite', '^(?!nova).*$'); The controller shouldn't matter as it's never reached. I dd'd the variables in the anyPage function and still get a 404 instead of any output. – asto Feb 07 '19 at 11:42
  • I also don't see why the regex would be catching the / character .. it should only look for the appearance of the word **nova** – asto Feb 07 '19 at 12:45
  • @asto the `*` character in RegEx is greedy, which means it will match as many characters as possible, including forward slashes. The regex in the original question is looking for as many characters as possible where the string doesn't begin with `nova`: so, "blog/news" is being passed to the `seite` parameter, and the `sweit` and `dritt` parameters are never matched. Something like `^(?!nova)[^\/]*` would grab the everything except the slash. – Tomy Smith Sep 30 '19 at 15:11