Routing: Omitting everything but uid

I’m trying to implement a similar feature, but not throughout the whole site, only on a specific folder.

The folder structure is:


    • issue-1
    • issue-2
    • …etc
    • issue-18
      • article

And I want all article urls to be ‘’ instead of ‘’.

Have been reading about routes and lots of helpful posts on here, but am missing something, as I have got everything directing to ‘’ but it’s showing the error page.

Here’s my latest attempt, any pointers would be much appreciated!

c::set('routes', array(
    'pattern' => 'magazine/(:any)',
    'action'  => function($uid) {

      $page = page($uid);

      if(!$page) $page = page('magazine/issue-' . str::substr($uid, 5) . '/' . $uid);
      if(!$page) $page = site()->errorPage();

      return site()->visit($page);

     'pattern' => 'magazine/(:any)/(:any)',
     'action'  => function($issue, $article) {
       return go($article);

Edit: The page ‘’ must still work, and would it be possible to have ‘’ also still work?