$config = [
// ...
'params' => require(__DIR__ . '/params.php'),
// redirect to the page with the trailing slash
'on beforeRequest' => function () {
$app = Yii::$app;
$pathInfo = $app->request->pathInfo;
if (!empty($pathInfo) && substr($pathInfo, -1) !== '/') {
$app->response->redirect('/' . rtrim($pathInfo) . '/', 301);
}
},
];