Slim 3.8 框架无法路由

Posted

技术标签:

【中文标题】Slim 3.8 框架无法路由【英文标题】:Slim 3.8 framework failing to route 【发布时间】:2018-03-08 18:56:17 【问题描述】:

我使用 slim 已经有一段时间了,今天我更新到 3.8,开箱即用我发现了一些东西

 $app->get('/', function ($request, $response) 
 return 'Slim working';
);



$app->get('/hello', function ($request, $response) 
return 'Slim hello also working';
);

第一个方法调用有效,第二个给我Object not found! 错误,我不明白出了什么问题,谁能帮我理解。

所以我的文件夹结构就像appname/public/index.php 我运行第一个方法只需调用appname/public/ 来运行第二个我像appname/public/hello 一样运行它

【问题讨论】:

如果能附上错误sn-p就好了。 appname/public/index.php/hello 如果你没有重写 url 【参考方案1】:

您需要使用以下规则在根目录(很可能是 appname/public)中添加 .htaccess 文件

RewriteEngine On

RewriteCond %REQUEST_FILENAME !-d
RewriteCond %REQUEST_FILENAME !-f
RewriteRule ^ index.php [QSA,L]

希望它会起作用。

【讨论】:

太棒了。谢谢!!

以上是关于Slim 3.8 框架无法路由的主要内容,如果未能解决你的问题,请参考以下文章