From 975704b3336b79362dff1ad2a029d9879e31b25e Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 28 Oct 2025 14:37:38 +0100 Subject: [PATCH] Fix bootstrap config loading and root rewrites --- .htaccess | 15 ++++++++++++--- bootstrap/helpers.php | 8 ++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/.htaccess b/.htaccess index c367759..31f4bc2 100644 --- a/.htaccess +++ b/.htaccess @@ -1,10 +1,19 @@ RewriteEngine On + RewriteBase / - # Redirect all requests to the public directory where the front controller lives - RewriteCond %{REQUEST_URI} !^/public/ + # Allow direct access to files that actually exist in the public directory + RewriteCond %{DOCUMENT_ROOT}/public/$1 -f RewriteRule ^(.*)$ public/$1 [L] + + RewriteCond %{DOCUMENT_ROOT}/public/$1 -d + RewriteRule ^(.*)$ public/$1/ [L] + + # Block direct access to sensitive directories + RewriteRule ^(app|bootstrap|config|database|resources|routes)/ - [F,L] + + # Everything else goes through the front controller + RewriteRule ^ public/index.php [QSA,L] -# Ensure the public front controller is used as the default directory index DirectoryIndex public/index.php diff --git a/bootstrap/helpers.php b/bootstrap/helpers.php index d06142c..92d6382 100644 --- a/bootstrap/helpers.php +++ b/bootstrap/helpers.php @@ -2,6 +2,14 @@ use App\Core\Config; +// Ensure the configuration class is loaded even if SPL autoloading is not yet available +if (!class_exists(Config::class, false)) { + $configPath = __DIR__ . '/../app/Core/Config.php'; + if (file_exists($configPath)) { + require_once $configPath; + } +} + if (!function_exists('config')) { function config(string $key, $default = null) {