Servus
I have a very simple content structure for a blog I am creating. Under /content/2_blog I create articles in a multi-language site environment.
So when I create a new article with the title “I love kirby” the URL gets generated as
https://blog.mysite/blog/2024-06-26-i-love-kirby
I guess it is obvious why, but I want to get rid of the “blog” in the URL. That is why, after researching, I did two things.
First, I added the following to my config.php:
'routes' => [
// Let's get rid of the "blog" in the URL
[
'pattern' => '(:any)',
'language' => '*',
'action' => function($uid) {
$page = page($uid);
if(!$page) $page = page('blog/' . $uid);
if(!$page) $page = site()->errorPage();
return site()->visit($page);
}
],
[
'pattern' => 'blog/(:any)',
'language' => '*',
'action' => function($uid) {
go($uid);
}
],
[...]
Also, I created an article.php in site/models:
<?php
use Kirby\Cms\Url;
class ArticlePage extends Page
{
public function urlForLanguage($language = null, array $options = null): string
{
if ($language === null || $this->kirby()->defaultLanguage()->code() === $language) {
return $this->url = $this->site()->urlForLanguage($language) . '/' . $this->slug($language);
}
return parent::urlForLanguage($language, $options);
}
}
Now in my panel, when opening the article it still shows the URL including the “blog” which I do not mind:
What I do mind is that after my two changes described above, the “blog” gets successfully removed from the URL when I click to Preview the article from the panel but it I end up getting a 404 File Not Found Error.
Where is my mistake?
Any input is highly welcome.
Thanks
Andreas