Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
adrianocr opened this issue Aug 7, 2018 · 2 comments
Open

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

adrianocr opened this issue Aug 7, 2018 · 2 comments

Comments

@adrianocr
Copy link

adrianocr commented Aug 7, 2018

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?

@lablnet

This comment has been minimized.

@koenpunt
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants