Changing Home doesn't work anymore


#1

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.


#2

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


#3

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'
];

#4

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


#5

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?


#6

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?


#7

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

#8

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.


#9

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