getUri(); $path = $uri->getPath(); if ('/' != $path && '/' == substr($path, -1)) { // recursively remove slashes when its more than 1 slash $path = rtrim($path, '/'); // permanently redirect paths with a trailing slash // to their non-trailing counterpart $uri = $uri->withPath($path); if ('GET' == $request->getMethod()) { return $this->responseFactory->createResponse(301)->withHeader('Location', (string) $uri); } else { $request = $request->withUri($uri); } } return $handler->handle($request); } }