From 839f0ff89c735c8e202f98b85dd1724b5770f7b8 Mon Sep 17 00:00:00 2001 From: Niek ten Hoopen Date: Mon, 29 Jul 2024 19:21:34 +0200 Subject: [PATCH] Bugfix for #469 that was introduced iin 4.2.2 --- src/models/data/SeoData.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/models/data/SeoData.php b/src/models/data/SeoData.php index 04158c4..a1eddf4 100644 --- a/src/models/data/SeoData.php +++ b/src/models/data/SeoData.php @@ -377,9 +377,14 @@ 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']); }