diff --git a/engine/core/class/CodePressCMS.php b/engine/core/class/CodePressCMS.php index 1623671..2c292e1 100644 --- a/engine/core/class/CodePressCMS.php +++ b/engine/core/class/CodePressCMS.php @@ -230,9 +230,10 @@ class CodePressCMS { } $page = $_GET['page'] ?? $this->config['default_page']; - $page = preg_replace('/\.[^.]+$/', '', $page); + // Only remove file extension at the end, not all dots + $pageWithoutExt = preg_replace('/\.(md|php|html)$/', '', $page); - $filePath = $this->config['content_dir'] . '/' . $page; + $filePath = $this->config['content_dir'] . '/' . $pageWithoutExt; $actualFilePath = null; // Check for exact file matches first @@ -261,21 +262,21 @@ class CodePressCMS { if (!isset($result)) { $langPrefix = $this->currentLanguage; - if (file_exists($this->config['content_dir'] . '/' . $langPrefix . '.' . $page . '.md')) { - $actualFilePath = $this->config['content_dir'] . '/' . $langPrefix . '.' . $page . '.md'; + if (file_exists($this->config['content_dir'] . '/' . $langPrefix . '.' . $pageWithoutExt . '.md')) { + $actualFilePath = $this->config['content_dir'] . '/' . $langPrefix . '.' . $pageWithoutExt . '.md'; $result = $this->parseMarkdown(file_get_contents($actualFilePath)); - } elseif (file_exists($this->config['content_dir'] . '/' . $langPrefix . '.' . $page . '.php')) { - $actualFilePath = $this->config['content_dir'] . '/' . $langPrefix . '.' . $page . '.php'; + } elseif (file_exists($this->config['content_dir'] . '/' . $langPrefix . '.' . $pageWithoutExt . '.php')) { + $actualFilePath = $this->config['content_dir'] . '/' . $langPrefix . '.' . $pageWithoutExt . '.php'; $result = $this->parsePHP($actualFilePath); - } elseif (file_exists($this->config['content_dir'] . '/' . $langPrefix . '.' . $page . '.html')) { - $actualFilePath = $this->config['content_dir'] . '/' . $langPrefix . '.' . $page . '.html'; + } elseif (file_exists($this->config['content_dir'] . '/' . $langPrefix . '.' . $pageWithoutExt . '.html')) { + $actualFilePath = $this->config['content_dir'] . '/' . $langPrefix . '.' . $pageWithoutExt . '.html'; $result = $this->parseHTML(file_get_contents($actualFilePath)); } } // If no file found, check if it's a directory if (!isset($result) && is_dir($filePath)) { - return $this->getDirectoryListing($page, $filePath); + return $this->getDirectoryListing($pageWithoutExt, $filePath); } if (isset($result) && $actualFilePath) {