AltoRouter icon indicating copy to clipboard operation
AltoRouter copied to clipboard

Is there a way to force a route format? Like a /pages/ subdir

Open adrianocr opened this issue 7 years ago • 2 comments

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?

adrianocr avatar Aug 07 '18 18:08 adrianocr

use https://github.com/Lablnet/ZestRouter

lablnet avatar Aug 21 '18 09:08 lablnet

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;
});

koenpunt avatar Aug 22 '18 22:08 koenpunt