# Rerouting for cleaner URLs

**URL:** <https://forum.getkirby.com/t/rerouting-for-cleaner-urls/17831>\
**Category:** Questions\
**Tags:** v3\
**Created:** [April 9, 2020, 12:15pm UTC](https://forum.getkirby.com/t/rerouting-for-cleaner-urls/17831 "2020-04-09T12:15:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Walter](https://avatars.discourse-cdn.com/v4/letter/w/85e7bf/32.png) [@Walter](https://forum.getkirby.com/u/Walter)\
**Post date:** [April 9, 2020, 12:15pm UTC](https://forum.getkirby.com/t/rerouting-for-cleaner-urls/17831/1 "2020-04-09T12:15:17Z")

</div>

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 [Routes | Kirby CMS](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!

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [April 9, 2020, 12:29pm UTC](https://forum.getkirby.com/t/rerouting-for-cleaner-urls/17831/2 "2020-04-09T12:29:42Z")

</div>

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](https://k2.getkirby.com/docs/developer-guide/advanced/routing#omitting-the-blog-folder-in-urls)

---

<div class="post-metadata">

**Author:** ![Walter](https://avatars.discourse-cdn.com/v4/letter/w/85e7bf/32.png) [@Walter](https://forum.getkirby.com/u/Walter)\
**Post date:** [April 9, 2020, 12:42pm UTC](https://forum.getkirby.com/t/rerouting-for-cleaner-urls/17831/3 "2020-04-09T12:42:46Z")

</div>

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