So, I’ve read through a few of the forum posts around custom routing, but I’m not quite getting it clear in my head,.
I have a custom route that looks like this:
'pattern' => '(:any)',
'action' => function ($uri) {
$originalURI = $uri;
$uri = cleanURL($uri);
// if we modified the url, redirect
if ($originalURI !== $uri) {
go($uri, 301);
}
// otherwise, load the page
return site()->visit($uri);
}
]
This does what I want it to, namely the URI’s get ‘cleaned’ and then redirected when the URI is “dirty”. (in this case dirty means it has umlauts, a trailing slash, and/or upper case characters.
If however the URI is already “clean,” I’d like normal routing to take place, instead of just showing the page.
The way it is now, things like the pattern plugin’s custom route to /patterns gets clobbered.
I could I suppose rewrite the pattern field in the route to not match on /patterns, but I’d rather have a more all encompassing solution.
The last thing I’ve tried is this, and it kinda works even though I still get an error on the /patterns page.
[
'pattern' => '(.*)',
'action' => function ($uri) {
go(cleanURL($uri), 301);
},
'filter' => function ($route) {
$path = $route->arguments[0];
if ($path === cleanURL($path) || $path === '/') {
return false;
}
return true;
},
]
Am I just approaching this wrong? This doesn’t feel ‘right’ somehow.