Help me understand/implement these permalink schemes!

Hello all o/

Making a website for myself, I’m used to Hugo where we can specify the permalink scheme for a section in sitewide config. So I had it as follows:
Posts in /content/ and /content/work/ would render at https://example.com/filename/
Posts in /content/journal/ and /content/weblog/would render at https://example.com/YYYY/MM/DD/

How do we do this in Kirby? Please nudge me in a better direction than whatever I’m currently doing! I’m extremely new to web development and don’t know where exactly to look.

By default, Kirby’s URL scheme is based on the folder structure:

content/
  home/
  blog/
    article-1/

render as
home: https://example.com
blog : https://example.com/blog
article 1: https://example.com/blog/article-1
etc. with pages further down the tree following the same scheme.

It is possible to diverge from this theme using Kirby’s router, see Routing | Kirby CMS, to create all sorts of different URL schemes. Best in combination with page models that modify the url() method to render the desired url.

So if you want to keep your current scheme, you would have to use the router.

An alternative would be to reroute existing Urls to Kirby’s url pattern.

I couldn’t make sense of the configs on the Routing page. I see an example in the demokit that I still can’t comprehend. Do you know of any other examples?

Anyway, thanks for the reply! I’ll look around more.

Maybe you can show your current content folder setup in Kirby and then tell me what Url scheme you want instead of the one you get, then we can take that as an example.

I was going for a learn-and-then-make approach, so don’t have anything at the moment. Guess I’ll learn a bit more PHP and web servers and try again after a while. Thank you!

How difficult would this be?

Content dir:

├── about/page.txt
├── contact/page.txt
├── now/page.txt
└── journal/list.txt
    ├── 20231009_short-title/post.txt
    ├── 20231010_title/post.txt
    └── 20231011_title/post.txt

Desired output:

├── /about/index.html
├── /contact/index.html
├── /now/index.html
└── /2023/
    └── /10/
        ├── /09/index.html
        ├── /10/index.html
        └── /11/index.html

It’s not really difficult, however, the journal entries rely on the fact that there is only one post per day, otherwise, you would end up with the same URL twice.

Do you only want to use this as permalinks? Or also as default URLs?

For the journal page to respond to your desired pattern, a route would look this this:

'routes' => [
	[
		'pattern' => '(:num)/(:num)/(:num)/index.html',
		'action'  => function ($year, $month, $day) {
			if ($p = page('journal')
				->children()
				->listed()
				->findBy('date', $year . '-' . $month . '-' . $day)) {
				return $p;
			}

			$this->next();
		},
	],
],

If needed, you could finetune the pattern and instead of the :num placeholder use regex strings with the exact number of numbers in the placeholder.

So what this does: If someone visits the address https://example.com/2023/10/09/index.html, the route will intercept this call, and then check if a page with the given date value in the date field exists and return this page, otherwise go to the next applicable route (which probably doesn’t exist and then return the error page).

Thank you very much for this! Let me try…