Compare commits

..

1 Commits

Author SHA1 Message Date
Jérémy Dufraisse
1c89b6cb4f fix(App/rewrite): detect when at root 2023-12-25 17:19:04 +01:00

30
App.php
View File

@ -173,7 +173,10 @@ class App
$config['rewrite_url'] = true;
$nbLevels = count(explode('/',$configDir.$requestUrl));
} elseif (!empty($_SERVER['SCRIPT_NAME']) && substr($_SERVER['SCRIPT_NAME'],-strlen($supposedEndUrlForNotRewrite)) == $supposedEndUrlForNotRewrite) {
$config['rewrite_url'] = true;
$nbLevels = count(explode('/',$configDir)) -1;
} else {
$this->appendContentToServerfNeeded($nbLevels,$config);
}
} elseif (!empty($_SERVER['SCRIPT_NAME']) && is_string($_SERVER['SCRIPT_NAME'])) {
$matches = [];
@ -193,6 +196,8 @@ class App
}
$nbLevels = count(explode('/',$configDir)) -1;
$config['rewrite_url'] = true;
} else {
$this->appendContentToServerfNeeded($nbLevels,$config);
}
}
}
@ -201,4 +206,29 @@ class App
$config['plugins_url'] = $previous.$config['plugins_url'];
$pico->setConfig($config);
}
/**
* append 'content' to $_SERVER var
* @param int &$nbLevels
* @param array &$config
* @return bool
*/
protected function appendContentToServerfNeeded(int &$nbLevels, array &$config): bool
{
if (!empty($_SERVER['SCRIPT_NAME']) && substr($_SERVER['SCRIPT_NAME'],-strlen('index.php')) == 'index.php' &&
!empty($_SERVER['SCRIPT_FILENAME']) &&
is_file(dirname($_SERVER['SCRIPT_FILENAME']).'/content/index.php')) {
if (!empty($_SERVER['SCRIPT_FILENAME'])){
$_SERVER['SCRIPT_FILENAME'] = str_replace('index.php','content/index.php',$_SERVER['SCRIPT_FILENAME']);
}
if (!empty($_SERVER['REQUEST_URI'])){
$_SERVER['REQUEST_URI'] = str_replace(['?','//content/'],['/content/?','/content/'],$_SERVER['REQUEST_URI']);
}
$_SERVER['SCRIPT_NAME'] = dirname($_SERVER['SCRIPT_NAME']).'/content/index.php';
$nbLevels = 1;
$config['rewrite_url'] = true;
return true;
}
return false;
}
}