getMethod()), ['get', 'head'], true)) { return null; } $path = trim(uri_string()); if ($path === '') { $path = trim($request->getUri()->getPath(), '/'); } // Skip files that legitimately end with a slash-like pattern or assets if ($path === '' || str_contains($path, '.')) { return null; } $needsRedirect = false; // trailing slash if (str_ends_with($path, '/')) { $path = rtrim($path, '/'); $needsRedirect = true; } // uppercase / mixed case if ($path !== mb_strtolower($path)) { $path = mb_strtolower($path); $needsRedirect = true; } // multiple consecutive slashes if (str_contains($path, '//')) { $path = preg_replace('#/+#', '/', $path); $needsRedirect = true; } if ($needsRedirect) { return redirect()->to($path !== '' ? '/' . ltrim((string) $path, '/') : '/') ->setStatusCode(301); } return null; } public function after(RequestInterface $request, ResponseInterface $response, $arguments = null) { return null; } }