Changing Home doesn't work anymore

Currently updating an “old” Kirby 2 Site.

I probably missed something but in the past it was possible to change the home to, lets say blog. So example.com/blog/ became example.com and example.com/blog/article-about-something became example.com/article-about-something and this worked out of the box by setting c::set(‘home’, ‘blog’) without setting up a route or a page model.

Now the Urls on the new home-page aka. blog do point to the right direction (the articles) but return a 404 and the articles are only reachable through the original url example.com/blog/article-about-something.

What do i miss, what has changed, how can I fix this?

Edit: I did try this also with a fresh install of the starter kit to test it and changed the homepage to notes with the same result.

According to this page in the docs you should be able to do exactly what you’re trying.

Just tested this in a fresh Starterkit and worked without any problems. Maybe it’s the old syntax that doesn’t work? Could you try the new way:

<?php

return [
    'debug' => true,
    'home' => 'notes'
];

It doesn’t and no I didn’t use an old syntax -> have you tried navigating on the notes pages to the subpages?

I got it to work - needed to setup a route which I didn’t need before:

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

        $page = page($uid);

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

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

      }
    ],
    [
      'pattern' => 'blog/(:any)',
      'action'  => function($uid) {
        go($uid);
      }
    ]
  ]
]

Is this behaviour expected?

Littel aside questions: I used to have routes, hooks etc. in separated files and required them in the config.php - at first glance this is not longer possible with the new return syntax or am I wrong?

Yes, you can move options to external files and require them in the main config file.

<?php // site/config/config.php

return [
    // ...
    'routes'  => require_once __DIR__ . '/routes.php',
];

Make sure you return an array from the external file:

<?php // site/config/routes.php

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

Oh, I didn’t try subpage. But I actually consider this a bug as the redirect should be automatic without you having to add an additional route.

Thought so but I leave it up to you to open an issue, or should I?

the new 3.0.2-rc.1 fixes this problem!

Here is the closed issue https://github.com/getkirby/kirby/issues/1371