Unable to access page unless I enter trailing slash

Hi,

I’ve defined my routes like:

$app->get('/', function ($request, $response, $args) use ($app) {
});

And created multiple pages like this only.

Now, I can access the site if I type url like:
http://domain.com/user/

But I’m unable to access the page if I type url like:
http://domain.com/user

Is there any way to automatically change url from w/o trailing slash to w/ trailing slash ?

Thank you.

@bharat I’ve use this middleware for my apps and it works well:

https://www.slimframework.com/docs/cookbook/route-patterns.html

// removes last backslash so /route or /route/ will work
$app->add(function ($request, $response, $next) {
    $uri = $request->getUri();
    $path = $uri->getPath();

    if ($path != '/' && substr($path, -1) == '/') {
	    $uri = $uri->withPath(substr($path, 0, -1));
	    return $response->withRedirect((string)$uri, 301);
    }
    return $next($request, $response);
});

Alternatively you could use this for your route:

$app->get('/user[/]','');

But you would have to do this on all of your routes.

@robrothedev, Thanks Rob :pray: