Skip to content

EspoCRM – Open Source CRM Application

portal redirect trailing slash

Yuri Kuznetsov5d3245682038
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);
}