Trouble with a simple route to go back home

Hi there, I’m trying to figure out a way to get the user back to the homepage if they visit a page they shouldn’t.

 [
                'pattern' => '/commandes',
                'action'  => function () {
                    return go('home ', 301);
                }
            ]

This should be quite simple but I can’t seem to make it work?

Thanks for the help!

Should work (although I’d remove the whitespace after home). i.e. user visiting the command path should get redirected. I’d be careful with 301 redirects though, but that’s just on a side note.

Is your site single or multi-lang? Maybe something wrong with your route syntax, hard to tell from the snippet without context.

That’s very weird then… The website is not multilang.
But when I visite localhost:8000/commandes it doesn’t do anything…
Here is the complete config file :

<?php


return [
    'debug'  => true,
    'panel' => [
        'css' => 'assets/css/custom-panel.css',

        'routes' => [


            [
                'pattern' => 'sitemap.xml',
                'action'  => function () {
                    $pages = site()->pages()->index();

                    // fetch the pages to ignore from the config settings,
                    // if nothing is set, we ignore the error page
                    $ignore = kirby()->option('sitemap.ignore', ['error', 'collections']);

                    $content = snippet('sitemap', compact('pages', 'ignore'), true);

                    // return response with correct header type
                    return new Kirby\Cms\Response($content, 'application/xml');
                }
            ],
            [
                'pattern' => 'sitemap',
                'action'  => function () {
                    return go('sitemap.xml', 301);
                }
            ],
            [
                'pattern' => '/commandes',
                'action'  => function () {
                    return go('home ', 301);
                }
            ]
        ]
    ]
];

Your routes are within the panel array, that doesn’t make sense. Close the array after the css option. Then again, remove the whitespace after home and remove the unnecessary preceding slash from the pattern.