Change of url, how do I redirect tags?

Hey folks,

I recently changed the structure of my blog slightly, now posts are children of /blog/ rather than children of root.

I’m trying to create a route in my config that redirects /tag:<anything> to /blog/tag:`.

Here’s what I’ve come up with, but it doesn’t seem to be working:

// Redirect tags
        [
            'pattern' => 'tag:(:any)',
            'action'  => function ($tag) {
                return go('blog/tag:' . $tag);
            }
        ],

What am I doing wrong?

Thanks,

Kev

Parameters cannot be part of a route pattern. So you would need a route that answers to the root /, then check if the request contains parameters (kirby()->request()->params()->tag())

Ah, ok, thanks Sonja. I came up with this, which seems to be working correctly:

// Redirect tags
        [
            'pattern' => '/',
            'action'  => function () {
                $tag = kirby()->request()->params()->get('tag');
                if ($tag) {
                    return go('blog/tag:' . $tag);
                }
                return page('home');
            }
        ],