Rerouting for cleaner URLs

Hi,
this should be a quick one.

I’d like to shorten my URLs from mywebsite.com/projects/myproject-1 to mywebsite.com/myproject-1. I understand that this should be possible using the inbuilt routing functionality https://getkirby.com/docs/guide/routing and think that I need this code in my config.php to catch the pattern:

 return [
   'routes' => [
     [
       'pattern' => '/projects',
       'action'  => function () {
         // do something here
         // when the URL matches the pattern above
       }
     ]
   ]
 ];

But I can’t figure out how to actually reroute the URL in the “action” part of the code.

Would be glad about some help.
Thanks!

Basically you need two routes like in this old Kirby 2 example: https://k2.getkirby.com/docs/developer-guide/advanced/routing#omitting-the-blog-folder-in-urls

Thanks, this did the trick!

'routes' => [
    	[
	      'pattern' => '(:any)',
	      'action'  => function ($uid) {
	        $page = page($uid);

	      if(!$page) $page = page('projects/' . $uid);
	      if(!$page) $page = site()->errorPage();

	      return site()->visit($page);
	      }
    	],
  
	    [
	      'pattern' => 'projects/(:any)',
	      'action'  => function($uid) {
	      go($uid);
	      }
	    ]
	]