Search code examples
phpurl-routingslim

Slim trailing slash route


I have this route in a Slim application:

$app->get('/fasi/:id/',function ($id) use ($app) {
        $app->render("fasi.html");
});

This answers to

http://test/fasi/1/

but also to

http://test/fasi/1

Is there any way to force Slim to answer only to the url with the trailing slash (first one) or, to redirect the client adding the trailing slash?


Solution

  • You can make optional the slash and the parameter also, like this:

    $app->get('/fasi/[:id[/]]',function ($id) use ($app) {
        $app->render("fasi.html");
    });
    

    This works with:

    http://test/fasi/1

    or:

    http://test/fasi/1/