Skip to content

Commit 2e828ba

Browse files
committed
Bugfix: Use only protocol and host as base for rules
1 parent ebac107 commit 2e828ba

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

Classes/Http/DomainRedirectMiddleware.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,15 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
5252
if (preg_match('#^https?://#', $replacement)) {
5353
$targetUrl = preg_replace('#' . $rule['pattern'] . '#', $replacement, $path);
5454
} else {
55-
// If replacement is a path, build full URL from target domain
55+
// If replacement is a path, build full URL from target domain (without path)
5656
$targetPath = preg_replace('#' . $rule['pattern'] . '#', $replacement, $path);
57-
$targetUrl = isset($redirect['target']) ? rtrim($redirect['target'], '/') . $targetPath : $targetPath;
57+
if (isset($redirect['target'])) {
58+
$parsedTarget = parse_url($redirect['target']);
59+
$targetBase = ($parsedTarget['scheme'] ?? 'https') . '://' . ($parsedTarget['host'] ?? '');
60+
$targetUrl = rtrim($targetBase, '/') . $targetPath;
61+
} else {
62+
$targetUrl = $targetPath;
63+
}
5864
}
5965

6066
return $this->createRedirectResponse($targetUrl, $statusCode);

0 commit comments

Comments
 (0)