Optional route params error on production, not locally. Not sure if bug


So I’ve been developing a small modular app locally, my local environment mirrors production as closely as possible (same php version, same OS and version). Production is on EC2.

Now I deployed to production, and on my module routes I received Page Not Found, everywhere.
After hours of debugging I figured out that it was the optional route parameters:

$app->group('', function () {
    $this->get('/', '\Klever\Modules\Apps\Controllers\ContentController:index')->setName('home');
    $this->get('/apps[/{slug}[/]]', '\Klever\Modules\Apps\Controllers\ContentController:show')->setName('detail');
    $this->get('/category[/{slug}[/]]', '\Klever\Modules\Apps\Controllers\CategoryController:index')->setName('categories');
    $this->get('/search[/{term}]]', '\Klever\Modules\Apps\Controllers\SearchController:index')->setName('search');

The category and search route are loaded in every Twig view.

When I switch the optional part and make it required, it all starts to work:

$app->group('', function () {
    $this->get('/', '\Klever\Modules\Apps\Controllers\ContentController:index')->setName('home');
    $this->get('/apps/{slug}[/]', '\Klever\Modules\Apps\Controllers\ContentController:show')->setName('detail');
    $this->get('/category/{slug}[/]', '\Klever\Modules\Apps\Controllers\CategoryController:index')->setName('categories');
    $this->get('/search/{term}[/]', '\Klever\Modules\Apps\Controllers\SearchController:index')->setName('search');

I’m honestly still not sure why it doesn’t work on production with the optional parameters, and secretly hope it’s something obvious you guys will tell me, so that I can find peace :slight_smile:

Routes are like this:

This route works with optional or required params on my local setup, but in production it only works when I remove the optional parts.


Usually / and [/] are unnecessary as the last character in a route.