Add date to url of post


i want to display the year of the publishing date of a single blog post in the url to the post, but i don’t know how. I’m using the new Starterkit as reference.


What is your expected URL pattern?

Oh, sorry, forgot to mention.
I expect “

Ok, unless you actually put your articles into year folders, the way to achieve this would be to use routes in combination with a custom URL method in a page model that overwrites the default url() method.

In fact, it would be great if only one pattern was defined for custom urls and integrated with the router :+1:

Are you able to provide some guidance on this?

I am trying to achieve this outcome.

Current url: /parent/child

Desired url: /authors-of-child/child

Where authors-of-child is just a field from the child page, stored as a tag(s). The “author” field usually contains only one name in the format 'FirstName LastName but occassionally will have more than one author.

Thanks in advance!

Does this mean if there are multiple authors, those authors should be stringed together?

Basically, you need two routes:

  1. The first one listens to your desired URL and then finds and returns the subpage if it exists
  2. The second route redirects the real URL to the target url

I’m assuming your parent page is called blog.

  'routes' => [
            'pattern' => '(:any)/(:any)',
            'action' => function ($author, $subpage) {
                if ($page = page('blog')->find($subpage)) {
                  return $page;
            'pattern' => 'blog/(:any)',
            'action' => function ($slug) {
                if ($page = page('blog/' . $slug)) {
                    $author = Str::slug(implode(' ', $page->authors()->split(',')));
                    go($author . '/' . $slug);

(not tested)

Ideally, you would also create a Page model that rewrites the URL to the target URL, so that the redirect is not necessary.