From cbdf464599dc2eb1988ec257c5ea863e775c73d4 Mon Sep 17 00:00:00 2001 From: Jacek Pyziak Date: Sun, 27 Oct 2024 21:49:59 +0100 Subject: [PATCH] Update htaccess to include rewrite rules for non-existing files and directories --- autoload/class.S.php | 5 +++++ index.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/autoload/class.S.php b/autoload/class.S.php index 71e04c1..6d14e85 100644 --- a/autoload/class.S.php +++ b/autoload/class.S.php @@ -769,6 +769,11 @@ class S $htaccess_data ); } + $htaccess_data .= PHP_EOL; + $htaccess_data .= 'RewriteCond %{REQUEST_FILENAME} !-f' . PHP_EOL; + $htaccess_data .= 'RewriteCond %{REQUEST_FILENAME} !-d' . PHP_EOL; + $htaccess_data .= 'RewriteRule ^ index.php [L]'; + $fp = fopen( $dir . '.htaccess', 'w' ); fwrite( $fp, $htaccess_data ); fclose( $fp ); diff --git a/index.php b/index.php index 870a0ba..e0ef074 100644 --- a/index.php +++ b/index.php @@ -103,7 +103,7 @@ if ( $request_uri != '' ) $pattern = $route['pattern']; $destination = $route['destination']; - if ( preg_match("#^" . $pattern . "#", $request_uri, $matches ) ) + if ( preg_match( "#^" . $pattern . "#", $request_uri, $matches ) ) { // Replace placeholders in the destination with matches from the request URI $destination = preg_replace( "#^" . $pattern . "#", $destination, $request_uri );