phplaravellumenlumen-routinglumen-5.4

Route with dot (IP address) not found, returns 404


I use Lumen 5.4.

This is how my route is setup:

$app->get('/ip/{ip}', GeoIpController::class . '@show');

The {ip} route parameter should be an IP address, with dots in it. However, it seems there is a problem when a route has dots in it. It returns a 404 not found error.

I am aware I could pass the IP address in as a simple GET request parameter, but want the IP to be part of the URL and to be handled like a route parameter.

For testing purposes, I use php -S localhost:8080 -t public to serve the application.


Solution

  • This is a limitation on PHP's built in server, not with Lumen (or Laravel, or Slim, or any other frameworks/apps with a router). You can view the PHP bug report here.

    Basically, if the URL has a dot in the url after the script name, the built-in server treats the request as a static file request, and it never actually attempts to run through the application.

    This request should work fine on a real web server (apache, nginx), but it will fail when run on PHP's built-in development web server.