找不到带点(IP地址)的路由,返回404 [英] Route with dot (IP address) not found, returns 404

查看:130
本文介绍了找不到带点(IP地址)的路由,返回404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Lumen 5.4.

这是我的路线设置方式:

This is how my route is setup:

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

{ip}路由参数应该是一个IP地址,其中带有点.但是,当路径中包含点时,似乎存在问题.它返回404 not found错误.

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.

我知道我可以将IP地址作为简单的GET请求参数传入,但希望IP成为URL的一部分并像路由参数一样进行处理.

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.

出于测试目的,我使用php -S localhost:8080 -t public服务该应用程序.

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

推荐答案

这是对PHP内置服务器的限制,而不是Lumen(或Laravel,Slim或带有路由器的任何其他框架/应用程序)的限制.您可以在此处查看 PHP错误报告.

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.

基本上,如果URL的脚本名称后面的URL中有一个点,则内置服务器会将请求视为静态文件请求,并且实际上不会尝试通过应用程序运行.

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.

此请求在真实的Web服务器(apache,nginx)上应该可以正常工作,但是在PHP的内置开发Web服务器上运行时将失败.

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.

这篇关于找不到带点(IP地址)的路由,返回404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆