Is it possible to redirect from an old page URL to new

We have changed the URL on one of our pages

www.example.com/shop/abc

to

www.example.com/shop/xyz

We’d like to set up an auto redirect from the old to the new (so that if someone had bookmarked the old URL they get redirected to the new URL).

Chat GPT says this can be done in the config.php file:

return [
    // Other configurations...

    'routes' => [
        [
            'pattern' => 'shop/abc',
            'action' => function () {
                return go('shop/xyz');
            }
        ],
    ],
];

Is this the case? It seems too simple to be true!

I’ve tried it and it works…

@texnixe Maybe we should add an example to Routes | Kirby CMS for go() as this might be a very common case for custom routes. Or would you see somewhere else in the docs better suited?

1 Like

I was under the impression that we had a redirect example, but yes, makes sense to add it and will do.

1 Like

That would be great. I did a search on the Kirby site for redirect but couldn’t find anything useful, so to have a specific example would be very useful I think.