URL change of child pages

I’ve build the site, uploaded to the server and everything is gravy.

I know that child pages take their parent page as their directory…

So… blog/page-name

I’ve managed to find a way to change this by using the config file…

'routes' => [
  'pattern' => 'post/(:any)',
  'action'  => function ($uid) { return page('blog/'.$uid); }

This gives me post/page-name and works great!

I could have done this via .htaccess file, but wanted the URL to look right in the browser bar.

Anyway, in my analytics (I use Fathom) I still see the old directory of /blog rather than the new one called /post.

If this something that could be resolved, or would I have to live with it messing with my analytics?

Cheers in advance!

Well, you do a simple redirect, however, you should actually use two routes for this use case:

  1. that does the redirect
  2. the one that returns the correct page

See: https://getkirby.com/docs/guide/routing#removing-the-parent-page-slug-from-the-url

In addition to that, you should modifiy what the url method returns. So create a page model for the subpage page type with the modified URL.