diff --git a/src/gql/resolvers/RetourResolver.php b/src/gql/resolvers/RetourResolver.php index bb3e806..be4e472 100644 --- a/src/gql/resolvers/RetourResolver.php +++ b/src/gql/resolvers/RetourResolver.php @@ -76,16 +76,15 @@ public static function resolve($source, array $arguments, $context, ResolveInfo 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 8306a15..48b6b0f 100644 --- a/src/services/Redirects.php +++ b/src/services/Redirects.php @@ -272,9 +272,21 @@ public function doRedirect(string $fullUrl, string $pathOnly, $redirect): bool 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; @@ -283,9 +295,8 @@ public function doRedirect(string $fullUrl, string $pathOnly, $redirect): bool $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) {