init bug rewrite

This commit is contained in:
fredtempez 2022-04-28 11:04:01 +02:00
parent ab37ed0ea9
commit cc8dcce9e3
5 changed files with 39 additions and 27 deletions

View File

@ -32,5 +32,4 @@ Options -Indexes
Options -MultiViews
</IfModule>
# Attention, surtout ne rien modifier ci-dessous !
# URL rewriting

View File

@ -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;
}

View File

@ -291,7 +291,6 @@ class common {
]);;
}
// Import version 9
if (file_exists(self::DATA_DIR . 'core.json') === true &&
$this->getData(['core','dataVersion']) < 10000) {

View File

@ -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 .
'<IfModule mod_rewrite.c>' . 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 .
'</IfModule>'. PHP_EOL .
'# URL rewriting' . PHP_EOL ;
$fileContent = str_replace('# URL rewriting', $rewriteData, $fileContent);
file_put_contents(
'.htaccess',
PHP_EOL .
'<IfModule mod_rewrite.c>' . 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 .
'</IfModule>',
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;
}

View File

@ -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 .
'<IfModule mod_rewrite.c>' . 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 .
'</IfModule>'. PHP_EOL .
'# URL rewriting' . PHP_EOL ;
$fileContent = str_replace('# URL rewriting', $rewriteData, $fileContent);
file_put_contents(
'.htaccess',
PHP_EOL .
'<IfModule mod_rewrite.c>' . 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 .
'</IfModule>',
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