diff --git a/.htaccess b/.htaccess index 5b415e20..6ebc6c9e 100644 --- a/.htaccess +++ b/.htaccess @@ -32,5 +32,4 @@ Options -Indexes Options -MultiViews -# Attention, surtout ne rien modifier ci-dessous ! # URL rewriting \ No newline at end of file diff --git a/core/class/helper.class.php b/core/class/helper.class.php index 43bb9a53..d74999af 100644 --- a/core/class/helper.class.php +++ b/core/class/helper.class.php @@ -267,7 +267,8 @@ class helper { // 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 = (empty($htaccess[1]) === false); + self::$rewriteStatus = (strpos($htaccess[1], 'RewriteEngine on') > 0) ? true : false; } return self::$rewriteStatus; } diff --git a/core/core.php b/core/core.php index a56bf873..3f374810 100644 --- a/core/core.php +++ b/core/core.php @@ -291,7 +291,6 @@ class common { ]);; } - // Import version 9 if (file_exists(self::DATA_DIR . 'core.json') === true && $this->getData(['core','dataVersion']) < 10000) { diff --git a/core/module/config/config.php b/core/module/config/config.php index 02ed0b45..d38ec9ce 100644 --- a/core/module/config/config.php +++ b/core/module/config/config.php @@ -547,17 +547,21 @@ class config extends common { AND helper::checkRewrite() === false ) { // Ajout des lignes dans le .htaccess + $fileContent = file_get_contents('.htaccess'); + $rewriteData = PHP_EOL . + '# URL rewriting' . PHP_EOL . + '' . PHP_EOL . + "\tRewriteEngine on" . PHP_EOL . + "\tRewriteBase " . helper::baseUrl(false, false) . PHP_EOL . + "\tRewriteCond %{REQUEST_FILENAME} !-f" . PHP_EOL . + "\tRewriteCond %{REQUEST_FILENAME} !-d" . PHP_EOL . + "\tRewriteRule ^(.*)$ index.php?$1 [L]" . PHP_EOL . + ''. PHP_EOL . + '# URL rewriting' . PHP_EOL ; + $fileContent = str_replace('# URL rewriting', $rewriteData, $fileContent); file_put_contents( '.htaccess', - PHP_EOL . - '' . PHP_EOL . - "\tRewriteEngine on" . PHP_EOL . - "\tRewriteBase " . helper::baseUrl(false, false) . PHP_EOL . - "\tRewriteCond %{REQUEST_FILENAME} !-f" . PHP_EOL . - "\tRewriteCond %{REQUEST_FILENAME} !-d" . PHP_EOL . - "\tRewriteRule ^(.*)$ index.php?$1 [L]" . PHP_EOL . - '', - FILE_APPEND + $fileContent ); // Change le statut de la réécriture d'URL (pour le helper::baseUrl() de la redirection) helper::$rewriteStatus = true; @@ -568,8 +572,13 @@ class config extends common { AND helper::checkRewrite() ) { // Suppression des lignes dans le .htaccess - $htaccess = explode('# URL rewriting', file_get_contents('.htaccess')); - file_put_contents('.htaccess', $htaccess[0] . '# URL rewriting'); + $fileContent = file_get_contents('.htaccess'); + $fileContent = explode('# URL rewriting', $fileContent); + $fileContent = $fileContent[0] . '# URL rewriting' . $fileContent[2]; + file_put_contents( + '.htaccess', + $fileContent + ); // Change le statut de la réécriture d'URL (pour le helper::baseUrl() de la redirection) helper::$rewriteStatus = false; } diff --git a/core/module/install/install.php b/core/module/install/install.php index 54f677c3..0145b020 100644 --- a/core/module/install/install.php +++ b/core/module/install/install.php @@ -252,19 +252,23 @@ class install extends common { $success = true; $rewrite = $this->getInput('data'); // Réécriture d'URL - if ($rewrite === "true") { - $success = (file_put_contents( + if ($rewrite === "true") { // Ajout des lignes dans le .htaccess + $fileContent = file_get_contents('.htaccess'); + $rewriteData = PHP_EOL . + '# URL rewriting' . PHP_EOL . + '' . PHP_EOL . + "\tRewriteEngine on" . PHP_EOL . + "\tRewriteBase " . helper::baseUrl(false, false) . PHP_EOL . + "\tRewriteCond %{REQUEST_FILENAME} !-f" . PHP_EOL . + "\tRewriteCond %{REQUEST_FILENAME} !-d" . PHP_EOL . + "\tRewriteRule ^(.*)$ index.php?$1 [L]" . PHP_EOL . + ''. PHP_EOL . + '# URL rewriting' . PHP_EOL ; + $fileContent = str_replace('# URL rewriting', $rewriteData, $fileContent); + file_put_contents( '.htaccess', - PHP_EOL . - '' . PHP_EOL . - "\tRewriteEngine on" . PHP_EOL . - "\tRewriteBase " . helper::baseUrl(false, false) . PHP_EOL . - "\tRewriteCond %{REQUEST_FILENAME} !-f" . PHP_EOL . - "\tRewriteCond %{REQUEST_FILENAME} !-d" . PHP_EOL . - "\tRewriteRule ^(.*)$ index.php?$1 [L]" . PHP_EOL . - '', - FILE_APPEND - ) !== false); + $fileContent + ); } // Recopie htaccess if ($this->getData(['config','autoUpdateHtaccess']) && @@ -272,7 +276,7 @@ class install extends common { ) { // L'écraser avec le backup $success = copy( '.htaccess.bak' ,'.htaccess' ); - // Effacer l ebackup + // Effacer le backup unlink('.htaccess.bak'); } // Valeurs en sortie