From 5d324568203801ec2b06bbc99b131c215f0f7827 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Fri, 8 Aug 2025 18:29:58 +0300 Subject: [PATCH] portal redirect trailing slash --- application/Espo/Core/Portal/Utils/Url.php | 19 +++++++++++++++++++ public/portal/index.php | 12 +++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/application/Espo/Core/Portal/Utils/Url.php b/application/Espo/Core/Portal/Utils/Url.php index f4acfef89c..aef98998dd 100644 --- a/application/Espo/Core/Portal/Utils/Url.php +++ b/application/Espo/Core/Portal/Utils/Url.php @@ -138,4 +138,23 @@ class Url return false; } + + public static function getRedirectUrlWithTrailingSlash(): ?string + { + $uri = $_SERVER['REQUEST_URI']; + + if ($uri === '' || $uri === '/' || str_ends_with($uri, '/')) { + return null; + } + + $output = $uri . '/'; + + $queryString = $_SERVER['QUERY_STRING'] ?? null; + + if ($queryString !== null && $queryString !== '') { + $output .= '?' . $_SERVER['QUERY_STRING']; + } + + return $output; + } } diff --git a/public/portal/index.php b/public/portal/index.php index c1a2b2eb1f..21a7550eb5 100644 --- a/public/portal/index.php +++ b/public/portal/index.php @@ -48,8 +48,18 @@ if (Url::detectIsInPortalDir()) { if (Url::detectIsInPortalWithId()) { $basePath = '../../'; - } + $redirectUrl = Url::getRedirectUrlWithTrailingSlash(); + + if ($redirectUrl) { + header('Location: ' . $redirectUrl, true, 301); + + exit; + } + } +} + +if ($basePath !== null) { $app->setClientBasePath($basePath); }