From 99aa1c80c800a233c15f29d5af7efc70aa44e2c7 Mon Sep 17 00:00:00 2001 From: Matteo Fogli Date: Tue, 21 May 2024 22:11:01 +0200 Subject: [PATCH] fix: regression on multisite canonical URLs --- src/models/data/SeoData.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/models/data/SeoData.php b/src/models/data/SeoData.php index e8076d5..a250760 100644 --- a/src/models/data/SeoData.php +++ b/src/models/data/SeoData.php @@ -377,8 +377,13 @@ public function getExpiry () */ public function getCanonical () { - if (empty($this->advanced['canonical'])) - return UrlHelper::siteUrl(Craft::$app->request->getFullPath()); + if (empty($this->advanced['canonical'])) { + $fullPathWithPagination = Craft::$app->request->getFullPath(); + $pathInfo = Craft::$app->request->getPathInfo(); + return ($subPath = strpos($fullPathWithPagination, $pathInfo . '/')) === false ? + UrlHelper::siteUrl($pathInfo) : + UrlHelper::siteUrl(substr($fullPathWithPagination, $subPath)); + } return UrlHelper::siteUrl($this->advanced['canonical']); }