Hi all,
I’m trying to write a route that is a negative of a pattern but I can’t get it to work, so I’m hoping for some tips.
So, I have this working fine:
$app->group(('/{locale:en-gb|en-us|fr-fr}', function() {
//.......
}
Within this group I have individual routes that are available for these locales. What I need to do is to have a route that doesn’t match these locales so that I can redirect to the browser’s preferred locale. If, once we get into that group, we still can’t match a route, then I want to 404
.
So I’m testing this on Regex101 and this works to match URLs link:
^/(en-gb|en-us|fr-fr)
(I’m using ` as the delimiter)
Sample URLs I’m testing:
/en-gb
/en-gb/test
/en-us
/en-us/false
/fr-fr
/fr-fr/foo
/false
/test
/foo/fr-fr
I can negate it with this regex link:
^/(?!(en-gb|en-us|fr-fr)).*
But I can’t get that to work as a route. Any ideas?