diff --git a/system/src/Grav/Common/Service/PagesServiceProvider.php b/system/src/Grav/Common/Service/PagesServiceProvider.php index c59a15c05..23f57328b 100644 --- a/system/src/Grav/Common/Service/PagesServiceProvider.php +++ b/system/src/Grav/Common/Service/PagesServiceProvider.php @@ -106,8 +106,12 @@ class PagesServiceProvider implements ServiceProviderInterface // Default route test and redirect $redirectCode = (int)$config->get('system.pages.redirect_default_route', 0); if ($redirectCode && \in_array($uri->method(), ['GET', 'HEAD'], true)) { - if ($route !== $path || \in_array($uri->extension(), ['htm', 'html'], true)) { - $grav->redirect($url, $redirectCode > 300 ? $redirectCode : null); + $urlExtension = $page->urlExtension(); + $uriExtension = $uri->extension(); + $uriExtension = null !== $uriExtension ? '.' . $uriExtension : ''; + + if ($route !== $path || ($urlExtension !== $uriExtension && \in_array($uriExtension, ['htm', 'html', null], true))) { + $grav->redirect($url . $urlExtension, $redirectCode > 300 ? $redirectCode : null); } } } diff --git a/system/src/Grav/Common/Uri.php b/system/src/Grav/Common/Uri.php index 9355d402a..22f6b861b 100644 --- a/system/src/Grav/Common/Uri.php +++ b/system/src/Grav/Common/Uri.php @@ -395,7 +395,7 @@ class Uri * Return the Extension of the URI * * @param string|null $default - * @return string The extension of the URI + * @return string|null The extension of the URI */ public function extension($default = null) {