From 0995fc8eea423fa5123401c63cd0779186330133 Mon Sep 17 00:00:00 2001 From: floppy0 <31189947+floppy0@users.noreply.github.com> Date: Fri, 2 Mar 2018 15:10:48 +0100 Subject: [PATCH] try to create the .htaccess --- install.php | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/install.php b/install.php index ed63c961..35935ccb 100644 --- a/install.php +++ b/install.php @@ -190,19 +190,36 @@ function checkSystem() $stdOut = array(); $dirpermissions = 0755; - // Check .htaccess file for different webservers - if (!file_exists(PATH_ROOT.'.htaccess')) { + // Try to create .htaccess file if not exists + $htaccessContent = 'AddDefaultCharset UTF-8 - if ( !isset($_SERVER['SERVER_SOFTWARE']) || - stripos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false || - stripos($_SERVER['SERVER_SOFTWARE'], 'LiteSpeed') !== false - ) { - $errorText = 'Missing file, upload the file .htaccess (ERROR_204)'; - error_log($errorText, 0); + - $tmp['title'] = 'File .htaccess'; - $tmp['errorText'] = $errorText; - array_push($stdOut, $tmp); +# Enable rewrite rules +RewriteEngine on + +# Deny direct access to .txt files +RewriteRule ^bl-content/(.*)\.txt$ - [R=404,L] + +# All URL process by index.php +RewriteCond %{REQUEST_FILENAME} !-f +RewriteRule ^(.*) index.php [PT,L] + +'; + + if ( !file_exists(PATH_ROOT.'.htaccess') || (filesize(PATH_ROOT.'.htaccess')<1) ) { + if (!file_put_contents(PATH_ROOT.'.htaccess', $htaccessContent)) { + if (!empty($_SERVER['SERVER_SOFTWARE'])) { + $webserver = Text::lowercase($_SERVER['SERVER_SOFTWARE']); + if (Text::stringContains($webserver, 'apache') || Text::stringContains($webserver, 'litespeed')) { + $errorText = 'Missing file, upload the file .htaccess (ERROR_204)'; + error_log($errorText, 0); + + $tmp['title'] = 'File .htaccess'; + $tmp['errorText'] = $errorText; + array_push($stdOut, $tmp); + } + } } }