我正在使用 PHP 5.4 RC5,并通过终端启动服务器
php -S localhost:8000
目前使用Aura.Router,在根目录下我有 index.php 文件和代码
<?php
$map = require '/Aura.Router/scripts/instance.php';
$map->add('home', '/');
$map->add(null, '/{:controller}/{:action}/{:id}');
$map->add('read', '/blog/read/{:id}{:format}', [
'params' => [
'id' => '(\d+)',
'format' => '(\.json|\.html)?',
],
'values' => [
'controller' => 'blog',
'action' => 'read',
'format' => '.html',
]
]);
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$route = $map->match($path, $_SERVER);
if (! $route) {
// no route object was returned
echo "No application route was found for that URI path.";
exit;
}
echo " Controller : " . $route->values['controller'];
echo " Action : " . $route->values['action'];
echo " Format : " . $route->values['format'];
要求http://localhost:8000/blog/read/1
按预期工作。
但是当点 json 或点 html 之类http://localhost:8000/blog/read/1.json
的http://localhost:8000/blog/read/1.html
请求到来时,php 会抛出
Not Found
The requested resource /blog/read/1.json was not found on this server.
当我使用内置的 php 服务器运行服务器时,我在哪里可以修复不抛出 html 和 json 文件未找到错误?
还是我想去安装 apache 并启用 mod rewrite 和东西?