From adf5db1a0a3b78cc51c5ba841b8194ffd831b123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Thu, 12 Sep 2019 21:41:38 +0200 Subject: [PATCH] Fixed redirection, when no locale and no valid path were given --- config/routes.yaml | 4 +++- src/Controller/RedirectController.php | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/config/routes.yaml b/config/routes.yaml index b77701d3..19c92250 100644 --- a/config/routes.yaml +++ b/config/routes.yaml @@ -7,4 +7,6 @@ redirector: path: /{url} requirements: url: ".*" - controller: App\Controller\RedirectController:addLocalePart \ No newline at end of file + controller: App\Controller\RedirectController:addLocalePart + # Dont match localized routes (no redirection loop, if no root with that name exists) + condition: "not (request.getPathInfo() matches '/\\\\/[a-z]{2}(_[A-Z]{2})?\\\\//')" \ No newline at end of file diff --git a/src/Controller/RedirectController.php b/src/Controller/RedirectController.php index 11176cea..b9d422a8 100644 --- a/src/Controller/RedirectController.php +++ b/src/Controller/RedirectController.php @@ -34,6 +34,7 @@ namespace App\Controller; use App\Entity\UserSystem\User; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; class RedirectController extends AbstractController { @@ -57,7 +58,8 @@ class RedirectController extends AbstractController } } - $new_url = str_replace($request->getPathInfo(), '/' . $locale . $request->getPathInfo(), $request->getUri()); + //$new_url = str_replace($request->getPathInfo(), '/' . $locale . $request->getPathInfo(), $request->getUri()); + $new_url = $request->getUriForPath('/' . $locale . $request->getPathInfo()); return $this->redirect($new_url); }