Removing home page folder from URL

Hi,

What is the best approach to remove the home page folder from the URL?
The subpage template is article.php.

I experimented with adding site/models/article.php

<?php
class ArticlePage extends Page {
    public function url($options = null): string {
    return $this->uid();
   }
}

It removes the folder from the URL but drops a 404 error on click.
And I just couldn’t create routing in the config that works.

Tried this logic, but it is definitely not good

'routes' => [
        [
          'pattern' => 'home/(:any)',
          'action'  => function ($slug) {
            return go('/' . $slug);
           }
        ],
      ]

Routing beats me every time.

Thank you in advance.

You need two routes, basically like described here, but with the Kirby 3 way of registering the routes:

https://k2.getkirby.com/docs/developer-guide/advanced/routing#omitting-the-blog-folder-in-urls

1 Like

Thank you very much, Sonja, of course, its working now, as always when you give a solution. :sunglasses:

If someone else needs this in future, Page Model is higher in the thread, and routing that works is this:

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

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

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

Just change home to your home page folder name, if you are using custom home page config.