I am using PHP 5.4 RC5, and starting the server via terminal
php -S localhost:8000
Currently using Aura.Router , and at the root I have index.php file with code
<?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'];
A request for http://localhost:8000/blog/read/1
works as expected.
But when a dot json or dot html like http://localhost:8000/blog/read/1.json
, http://localhost:8000/blog/read/1.html
request comes, the php throws
Not Found
The requested resource /blog/read/1.json was not found on this server.
As I am running the server with the built in php server, where can I fix not to throw the html and json file not found error ?
Or do I want to go and install apache and enable mod rewrite and stuffs ?