diff --git a/src/Controller/PageController.php b/src/Controller/PageController.php index 650e3fa2e66fd15390b51abf252999c8e26b6179..c2a8095382400f003d0af5703216dc0ef64223f0 100644 --- a/src/Controller/PageController.php +++ b/src/Controller/PageController.php @@ -8,12 +8,23 @@ use App\Repository\PageRepository; use App\Service\CaptchaService; use App\Service\PlaceholderService; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; class PageController extends AbstractController { + #[Route('/{all}.html', requirements: ['all' => '.*'], methods: ['GET'], priority: -1)] + public function redirectHtmlExtension(Request $request): Response + { + $path = $request->getPathInfo(); + if (str_ends_with($path, '.html')) { + $path = substr($path, 0, strlen($path) - 5); + } + return new RedirectResponse($path); + } + #[Route('/{all}', requirements: ['all' => '.*'], methods: ['GET'], priority: -1)] public function renderPage( Request $request, @@ -21,6 +32,7 @@ class PageController extends AbstractController CaptchaService $captchaService, PlaceholderService $placeholderService ): Response { + $page = $pageRepository->getPageFromURL($request->getPathInfo()); if (!$page) { return $this->render('pages/error404.html.twig')->setStatusCode(404);