Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit dc2ca9f

Browse files
Autodetect index file
1 parent b8754ef commit dc2ca9f

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

‎src/router.class.php‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,6 @@ function bootstrap()
370370
$uri_path = $this->URI_no_query();
371371
$uri_filepath = $_SERVER['DOCUMENT_ROOT'] . '/' . urldecode(substr($uri_path, 1));
372372

373-
374373
$load_index = $_SERVER['DOCUMENT_ROOT'] . "/" . $this->indexPath;
375374
$load_index = $this->format_unix(trim($load_index));
376375

@@ -679,6 +678,37 @@ function fix_path_info()
679678

680679
}
681680

681+
682+
/**
683+
* Autodetect index
684+
*/
685+
function autoDetectIndex()
686+
{
687+
688+
$indexRoot = $_SERVER["DOCUMENT_ROOT"] . '/' . $this->indexPath;
689+
690+
if (!file_exists($indexRoot)) {
691+
692+
$viableFilesForIndex = array('index.php', 'index.phtml', 'index.html', 'index.htm', 'index.html5', 'index.php5');
693+
694+
$scanRoot = scandir($_SERVER["DOCUMENT_ROOT"]);
695+
$scanRoot = array_filter($scanRoot, function ($k) use ($viableFilesForIndex) {
696+
return in_array(strtolower($k), $viableFilesForIndex);
697+
});
698+
$scanRoot = array_values($scanRoot);
699+
700+
if (count($scanRoot)) {
701+
702+
$this->indexPath = $scanRoot[0];
703+
704+
}
705+
706+
}
707+
708+
709+
}
710+
711+
682712
/**
683713
* Listen for requests
684714
* @return bool|mixed
@@ -690,9 +720,10 @@ function listen()
690720
$this->init();
691721
$this->log_output();
692722

693-
694723
$falsy_ext = $this->getExt($this->URI_no_query());
695724

725+
$this->autoDetectIndex();
726+
696727
if (in_array($falsy_ext, array("", "php"))) {
697728

698729
/**

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /