[Solved] Arguments not working properly in built-in server

PHP 5.6.12
Slim 3.1.0

Running the command:

php -S localhost:8000 test.php

With this code:

// test.php

require 'vendor/autoload.php';

$app = new \Slim\App;
$app->get('/{name}', function ($request, $response) {
    $name = $request->getAttribute('name');
    $response->getBody()->write("Hello, $name");
    return $response;
});
$app->run();

When I try GET “localhost:8000/foo” returns “Page not found”

But when i try: “localhost:8000/foo%20bar_after_space” returns correctly: “Hello, foo bar_after_space”.

Anyone know how to solve this?
Thanks

SOLUTION:

If i rename the file to “index.php”, run the code below and works… :neutral_face:

php -S localhost:8000 -t .

The built-in webserver has some rules:

If an index.php or index.html is found, it is returned and $_SERVER[‘PATH_INFO’] is set to the trailing part of the URI. Otherwise a 404 response code is returned.