Is there a way to force a route format? Like a /pages/ subdir
I want my '/' route to remain as is.
But if someone goes to anything other than '/' I have a wildcard route that grabs the name of that route, locates a twig file, and renders it based on name. So '/about' would locate about.twig and render it. It looks like this: [a:id]. I also have a /pages/[a:id] in case someone goes to '/pages/about', '/pages/contact', etc directly.
What I want to achieve is if someone goes to '/about' or '/contact', etc, then they'd be re-routed to '/pages/about', '/pages/contact', etc, but if they go to '/pages/about' directly then no re-route necessary.
But I how do I achieve that?
use https://github.com/Lablnet/ZestRouter
If you mean redirected by "re-routed", then you'll have to implement that yourself.
Something like this:
$router->match('GET', '/pages', function() {
// /pages redirects to /pages/about
header('Location: /pages/about');
exit;
});
$router->match('GET', '/pages/[a:id]', function($id) {
// /pages/* echos the id from the url
echo $id;
});