$requestedAbsoluteFile = rtrim(dirname(__FILE__) . $exploded_REQUEST_URI[0], "/");とかしてたら、
+ docroot1 | + index.phtml | + router.php + docroot2 + index.phtmlみたいな状態で docroot2 以下で
php -S localhost:8080 ../docroot1/router.phpみたいにした場合に docroot2/index.phtml が開けなかった(当たり前)。
<?php $indexFiles = ["index.phtml", "index.phtm"]; $exploded_REQUEST_URI = explode("?", $_SERVER["REQUEST_URI"]); $requestedAbsoluteFile = rtrim($_SERVER["DOCUMENT_ROOT"] . $exploded_REQUEST_URI[0], "/"); if (is_dir($requestedAbsoluteFile)) { foreach ($indexFiles as $filename) { $fn = $requestedAbsoluteFile.'/'.$filename; if (is_file($fn)) { $exploded_REQUEST_URI[0] = rtrim($exploded_REQUEST_URI[0],"/")."/".$filename; $url = implode("?", $exploded_REQUEST_URI); header("Location: ". $url, true, 307); return; } } } ini_set('default_charset', NULL); $ext = pathinfo($requestedAbsoluteFile, PATHINFO_EXTENSION); if (preg_match('/^(php|phtml|phtm)$/', $ext)) { $dir = getcwd(); chdir(dirname($requestedAbsoluteFile)); include($requestedAbsoluteFile); chdir($dir); } else if (preg_match('/^(html|htm)$/', $ext)) { readfile($requestedAbsoluteFile); } else { return FALSE; }