From 8131162dae9473723899602503212525efd0fa9c Mon Sep 17 00:00:00 2001 From: Fred Tempez Date: Sun, 9 Jun 2024 02:51:55 +0200 Subject: [PATCH] =?UTF-8?q?V=C3=A9rification=20de=20la=20r=C3=A9=C3=A9crit?= =?UTF-8?q?ure?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/class/helper.class.php | 7 +++---- core/module/config/config.php | 15 +++++++++++++++ core/module/config/view/setup/setup.php | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/core/class/helper.class.php b/core/class/helper.class.php index 445b07c..1992827 100644 --- a/core/class/helper.class.php +++ b/core/class/helper.class.php @@ -338,13 +338,12 @@ class helper { // N'interroge que le serveur Apache if (strpos($_SERVER["SERVER_SOFTWARE"], 'Apache') > 0) { - self::$rewriteStatus === false; - } elseif (self::$rewriteStatus === null) { + self::$rewriteStatus = false; + } else { // Ouvre et scinde le fichier .htaccess $htaccess = explode('# URL rewriting', file_get_contents('.htaccess')); // Retourne un boolean en fonction du contenu de la partie réservée à l'URL rewriting - //self::$rewriteStatus = (empty($htaccess[1]) === false); - self::$rewriteStatus = (strpos($htaccess[1], 'RewriteEngine on') > 0) ? true : false; + self::$rewriteStatus = (strpos($htaccess[1], 'RewriteEngine on') !== false); } return self::$rewriteStatus; } diff --git a/core/module/config/config.php b/core/module/config/config.php index d7a3229..b13e6b6 100644 --- a/core/module/config/config.php +++ b/core/module/config/config.php @@ -957,4 +957,19 @@ class config extends common ]); } } + + /** + * Fonction pour vérifier la présence du module de réécriture + * @return bool + */ + public function isModRewriteEnabled() { + // Check if Apache and mod_rewrite is loaded + if (function_exists('apache_get_modules')) { + $modules = apache_get_modules(); + return in_array('mod_rewrite', $modules); + } else { + // Fallback if not using Apache or unable to detect modules + return getenv('HTTP_MOD_REWRITE') == 'On' || getenv('REDIRECT_STATUS') == '200'; + } + } } \ No newline at end of file diff --git a/core/module/config/view/setup/setup.php b/core/module/config/view/setup/setup.php index b1e34e5..08ca40e 100644 --- a/core/module/config/view/setup/setup.php +++ b/core/module/config/view/setup/setup.php @@ -48,7 +48,7 @@ helper::checkRewrite(), 'help' => 'Supprime le point d\'interrogation dans les URL, l\'option est indisponible avec les autres serveurs Web', - 'disabled' => stripos($_SERVER["SERVER_SOFTWARE"], 'Apache') === false + 'disabled' => stripos($_SERVER["SERVER_SOFTWARE"], 'Apache') === false and $module->isModRewriteEnabled() ]); ?>