PHP 5.4内置服务器,修复文件未找到错误

我使用 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重写和东西?

解决方法

您正在尝试使用PHP内置Web服务器的路由器脚本而不指定它:

PHP -S localhost:8000

而是添加您的路由器脚本:

PHP -S localhost:8000 router.PHP

如果请求匹配,路由器脚本应该处理请求,或者它应该返回FALSE,以防它需要应用标准路由.比较Built-in web server­Docs.

我不知道Aura.Router是否支持开箱即用的内置Web服务器,或者是否要求您为其编写适配器.就像您需要为该路由器库配置Web服务器一样,您也需要配置内置Web服务器.这是上面示例中的router.PHP脚本.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...