diff --git a/App.php b/App.php index 824e541..5fd2030 100644 --- a/App.php +++ b/App.php @@ -172,7 +172,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 = []; @@ -192,6 +195,8 @@ class App } $nbLevels = count(explode('/',$configDir)) -1; $config['rewrite_url'] = true; + } else { + $this->appendContentToServerfNeeded($nbLevels,$config); } } } @@ -200,4 +205,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; + } } \ No newline at end of file