diff --git a/typo3/sysext/felogin/Classes/Controller/LoginController.php b/typo3/sysext/felogin/Classes/Controller/LoginController.php
index 47dfba47c642009946c2c8c0c60d674794541a8a..a216e3347bfbdfe4f60f79d31c7ffc3080984064 100644
--- a/typo3/sysext/felogin/Classes/Controller/LoginController.php
+++ b/typo3/sysext/felogin/Classes/Controller/LoginController.php
@@ -193,8 +193,11 @@ class LoginController extends AbstractLoginFormController
     protected function handleRedirect(): ?ResponseInterface
     {
         if ($this->redirectUrl !== '') {
-            $this->eventDispatcher->dispatch(new BeforeRedirectEvent($this->loginType, $this->redirectUrl));
-            return $this->redirectToUri($this->redirectUrl);
+            $event = new BeforeRedirectEvent($this->loginType, $this->redirectUrl, $this->request);
+            $this->eventDispatcher->dispatch($event);
+            if ($event->getRedirectUrl() !== '') {
+                return $this->redirectToUri($event->getRedirectUrl());
+            }
         }
         return null;
     }
diff --git a/typo3/sysext/felogin/Classes/Event/BeforeRedirectEvent.php b/typo3/sysext/felogin/Classes/Event/BeforeRedirectEvent.php
index 211e49cd7710c888353ecc8158c7a1ce6c1b0456..a8dffb715bcd3b29fa087d37dd7b153db3fc3206 100644
--- a/typo3/sysext/felogin/Classes/Event/BeforeRedirectEvent.php
+++ b/typo3/sysext/felogin/Classes/Event/BeforeRedirectEvent.php
@@ -17,14 +17,19 @@ declare(strict_types=1);
 
 namespace TYPO3\CMS\FrontendLogin\Event;
 
+use Psr\Http\Message\ServerRequestInterface;
+
 /**
- * Notification before a redirect is made.
+ * Notification before a redirect is made, which also allows to modify
+ * the actual redirect URL. Setting the redirect to an empty string
+ * will avoid triggering a redirect.
  */
 final class BeforeRedirectEvent
 {
     public function __construct(
         private readonly string $loginType,
-        private readonly string $redirectUrl
+        private string $redirectUrl,
+        private readonly ServerRequestInterface $request,
     ) {
     }
 
@@ -37,4 +42,14 @@ final class BeforeRedirectEvent
     {
         return $this->redirectUrl;
     }
+
+    public function setRedirectUrl(string $redirectUrl): void
+    {
+        $this->redirectUrl = $redirectUrl;
+    }
+
+    public function getRequest(): ServerRequestInterface
+    {
+        return $this->request;
+    }
 }