diff --git a/typo3/sysext/felogin/Classes/Controller/LoginController.php b/typo3/sysext/felogin/Classes/Controller/LoginController.php
index b8481a3b634f8c12028bcfe559699064765895c9..941ab8f97b637706688707a7344ae839d80baa38 100644
--- a/typo3/sysext/felogin/Classes/Controller/LoginController.php
+++ b/typo3/sysext/felogin/Classes/Controller/LoginController.php
@@ -251,8 +251,11 @@ class LoginController extends AbstractLoginFormController
     protected function handleRedirect(): void
     {
         if ($this->redirectUrl !== '') {
-            $this->eventDispatcher->dispatch(new BeforeRedirectEvent($this->loginType, $this->redirectUrl));
-            $this->redirectToUri($this->redirectUrl);
+            $event = new BeforeRedirectEvent($this->loginType, $this->redirectUrl, $this->request);
+            $this->eventDispatcher->dispatch($event);
+            if ($event->getRedirectUrl() !== '') {
+                $this->redirectToUri($event->getRedirectUrl());
+            }
         }
     }
 
diff --git a/typo3/sysext/felogin/Classes/Event/BeforeRedirectEvent.php b/typo3/sysext/felogin/Classes/Event/BeforeRedirectEvent.php
index d12c2927ffd9f226e24ded66314c681de74b53c0..bfa5151cb6e249e5d7c9a7a75030a0ff236f3b89 100644
--- a/typo3/sysext/felogin/Classes/Event/BeforeRedirectEvent.php
+++ b/typo3/sysext/felogin/Classes/Event/BeforeRedirectEvent.php
@@ -17,8 +17,12 @@ 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
 {
@@ -32,10 +36,16 @@ final class BeforeRedirectEvent
      */
     private $redirectUrl;
 
-    public function __construct(string $loginType, string $redirectUrl)
+    /**
+     * @var ServerRequestInterface
+     */
+    private $request;
+
+    public function __construct(string $loginType, string $redirectUrl, $request)
     {
         $this->loginType = $loginType;
         $this->redirectUrl = $redirectUrl;
+        $this->request = $request;
     }
 
     public function getLoginType(): string
@@ -47,4 +57,14 @@ final class BeforeRedirectEvent
     {
         return $this->redirectUrl;
     }
+
+    public function setRedirectUrl(string $redirectUrl): void
+    {
+        $this->redirectUrl = $redirectUrl;
+    }
+
+    public function getRequest()
+    {
+        return $this->request;
+    }
 }