Omit a variable letter or number in route

In my site, I have a basic ‘profiles’ section with profile pages, where there’s a subfolder for each first letter of the users, because else there will be +/- 900 pages in the /profile/ folder. The structure:

where /h/ is the first letter of the username, and this folder contains all profiles with ‘h’ as first letter of the username.

I would like to visit pages on the front-end like this:

So omitting the /h/ (or any letter or number) in the URL and still visit the right page :slight_smile: . There’s a guide ( on how to omit the ‘blog’ from a URL with two routes, but how can I do this with a variable folder name (will be 1 letter or number: a-z and 0-9) and still let all other pages work like normal?

That would be something like this:

c::set('routes', array(
    'pattern' => 'social/profile/[a-z0-9]/(:any)',
    'action'  => function($username) {
      go('social/profile/' . $username);
    'pattern' => 'social/profile/(:any)',
    'action'  => function($username) {
      $page = page($username);

      if(!$page) $page = page('social/profile/' . str::substr($username, 0, 1) . '/' . $username);
      if(!$page) $page = site()->errorPage();

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

Woohoo :slight_smile: That works! The str::substr($username, 0, 1) part is a clever solution that I didn’t thought of yet! Thanks for your help!