4

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.

patricus
  • 59,488
  • 15
  • 143
  • 145
wujt
  • 1,278
  • 2
  • 13
  • 21
  • From my experience with Laravel, I haven't seen a dot in a route parameter being an issue, however, I've also never started a route with `/`. As far as I know, routes are relative from the prefix (or / if no prefix is set), so `ip/{ip}` is what you should use. See if that fixes your 404. – Devon Bessemer May 19 '17 at 15:58
  • I'm afraid this request never reaches Lumen and it's killed by server somehow. – wujt May 19 '17 at 16:00
  • So the problem isn't related to Lumen then? What web server are you using? Any errors? Do you have it properly routed through your index.php? – Devon Bessemer May 19 '17 at 16:01
  • base encode the ip and decode it in the controller – Sandeesh May 19 '17 at 16:04
  • @Devon for testing purposes I use `php -S localhost:8080 -t public/` since Lumen hasn't got it's build-in server like Laravel. I didn't checked in on staging. There I have nginx. – wujt May 19 '17 at 16:52
  • @wujt use `php artisan serve` – Devon Bessemer May 19 '17 at 17:29
  • @Devon as I said, Lumen hasn't got it. – wujt May 19 '17 at 17:34

1 Answers1

12

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.

patricus
  • 59,488
  • 15
  • 143
  • 145