diff --git a/src/gql/resolvers/RetourResolver.php b/src/gql/resolvers/RetourResolver.php index a41aaca..c39dce3 100644 --- a/src/gql/resolvers/RetourResolver.php +++ b/src/gql/resolvers/RetourResolver.php @@ -76,16 +76,15 @@ public static function resolve(mixed $source, array $arguments, mixed $context, Retour::$plugin->statistics->incrementStatistics($uri, false, $siteId); } } - if ($redirect !== null) { - $dest = $redirect['redirectDestUrl']; - // If this isn't an absolute URL, make it one based on the appropriate site - if (!UrlHelper::isAbsoluteUrl($dest)) { - try { - $dest = UrlHelper::siteUrl($dest, null, null, $siteId); - $dest = parse_url($dest, PHP_URL_PATH); - } catch (Throwable $e) { - // That's ok - } + if ($redirect !== null && isset($redirect['redirectDestUrl'])) { + $path = $redirect['redirectDestUrl']; + // Combine the URL and path together, merging them as appropriate + try { + $dest = UrlHelper::siteUrl('/', null, null, $siteId); + $dest = UrlHelper::mergeUrlWithPath($dest, $path); + $dest = parse_url($dest, PHP_URL_PATH); + } catch (Throwable $e) { + // That's ok } $redirect['redirectDestUrl'] = $dest; } diff --git a/src/services/Redirects.php b/src/services/Redirects.php index 42d274c..fba1dbb 100644 --- a/src/services/Redirects.php +++ b/src/services/Redirects.php @@ -819,9 +819,21 @@ public function doRedirect(string $fullUrl, string $pathOnly, ?array $redirect): if ($redirect !== null) { // Figure out what type of source matching was done $redirectSrcMatch = $redirect['redirectSrcMatch'] ?? 'pathonly'; + $dest = $redirect['redirectDestUrl']; + $path = $redirect['redirectDestUrl']; switch ($redirectSrcMatch) { case 'pathonly': $url = $pathOnly; + try { + $siteId = $redirect['siteId'] ?? null; + if ($siteId !== null) { + $siteId = (int)$siteId; + } + $dest = UrlHelper::siteUrl('/', null, null, $siteId); + $dest = UrlHelper::mergeUrlWithPath($dest, $path); + $dest = parse_url($dest, PHP_URL_PATH); + } catch (\yii\base\Exception $e) { + } break; case 'fullurl': $url = $fullUrl; @@ -830,9 +842,8 @@ public function doRedirect(string $fullUrl, string $pathOnly, ?array $redirect): $url = $pathOnly; break; } - $dest = $redirect['redirectDestUrl']; - // If this isn't an absolute URL, make it one based on the appropriate site - if (!UrlHelper::isAbsoluteUrl($dest)) { + // If this isn't a full URL, make it one based on the appropriate site + if (!UrlHelper::isFullUrl($dest)) { try { $siteId = $redirect['siteId'] ?? null; if ($siteId !== null) {