<?php
// filename: route.php
if (preg_match('/\.(?:png|jpg|jpeg|gif|css|js)$/', $_SERVER["REQUEST_URI"])) {
return false;
} else {
include __DIR__ . '/index.php';
}
更好的写法:
<?php
// route.php
$filename = __DIR__.preg_replace('#(\?.*)$#', '', $_SERVER['REQUEST_URI']);
if (is_file($filename)) {
return false;
} else {
include __DIR__ . '/index.php';
}
命令行执行:
php -S localhost:8888 route.php