From 2a9046483c574e160bd5e323640714a5377a6c09 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Wed, 21 Feb 2024 13:37:16 -0500 Subject: [PATCH] fix: Fixed an issue where a trailing slash would be added to a paginated URL that uses URL parameters and `addTrailingSlashesToUrls` was `true` in the General config ([#1401](https://github.com/nystudio107/craft-seomatic/issues/1401)) --- src/helpers/UrlHelper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/helpers/UrlHelper.php b/src/helpers/UrlHelper.php index 67cf4eba4..833633675 100644 --- a/src/helpers/UrlHelper.php +++ b/src/helpers/UrlHelper.php @@ -50,7 +50,7 @@ public static function siteUrl(string $path = '', $params = null, string $scheme $url = self::mergeUrlWithPath($siteUrl, $path); // Handle trailing slashes properly for generated URLs $generalConfig = Craft::$app->getConfig()->getGeneral(); - if ($generalConfig->addTrailingSlashesToUrls && !preg_match('/\.[^\/]+$/', $url)) { + if ($generalConfig->addTrailingSlashesToUrls && !preg_match('/(.+\?.*)|(\.[^\/]+$)/', $url)) { $url = rtrim($url, '/') . '/'; } if (!$generalConfig->addTrailingSlashesToUrls) { @@ -151,7 +151,7 @@ public static function absoluteUrlWithProtocol($url): string // Handle trailing slashes properly for generated URLs $generalConfig = Craft::$app->getConfig()->getGeneral(); - if ($generalConfig->addTrailingSlashesToUrls && !preg_match('/\.[^\/]+$/', $url)) { + if ($generalConfig->addTrailingSlashesToUrls && !preg_match('/(.+\?.*)|(\.[^\/]+$)/', $url)) { $url = rtrim($url, '/') . '/'; } if (!$generalConfig->addTrailingSlashesToUrls) {