<?php
declare(strict_types=1);
use App\Application\Middleware\SessionMiddleware;
use Slim\App;
use Middlewares\TrailingSlash;
return function (App $app) {
$app->add(SessionMiddleware::class);
$app->add(new TrailingSlash(false));
}
to remove the trailing slash from url, but it returns a 404 when accessing /users/
Here is example with adding slash to all requests:
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;
use Slim\Exception\HttpNotFoundException;
use Psr\Http\Message\ServerRequestInterface;
use Slim\Psr7\Response as PsrResponse;
use Middlewares\TrailingSlash;
require __DIR__ . '/../slim/vendor/autoload.php';
$app = AppFactory::create();
$app->addRoutingMiddleware();
$app->add(new TrailingSlash(true));
$app->get('/user/', function (Request $request, Response $response) {
return $response;
});
$app->run();
/user and /user/ work well.
Do you add TrailingSlash(false) after $app->addRoutingMiddleware(); ?