Klein url router在XAMPP上不起作用


Klein url router not working on XAMPP

My app is on C:''xampp''htdocs''urlrouter''klein''

我使用作曲家安装了克莱因路由器。
而且,我将此脚本仅用于简单的基本路由

define('APP_PATH', '/urlrouter/klein/');
require_once 'vendor/autoload.php';
$request = 'Klein'Request::createFromGlobals();
$request->server()->set('REQUEST_URI', substr($_SERVER['REQUEST_URI'],  strlen(APP_PATH)));
$klein = new 'Klein'Klein();
$klein->respond('GET', '/hello', function () {
return 'Hello World!';
});
$klein->dispatch($request);

我也有这个.htaccess。

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L] 

但是,当我去http://localhost/urlrouter/klein/hello时,它会将我重定向到 XAMPP 主页或http://localhost/xampp/splash.php
我无法弄清楚这个路由器有什么问题。请帮助我

我从未尝试过用 Klein 操纵REQUEST_URI(不是说你不应该,只是警告缺乏专业知识),但你的 substr() 调用会产生"hello",其中你的路由模式是"/hello"。 这可能重要,也可能无关紧要(Klein 中的路由匹配逻辑有些复杂,我还没有内化它的所有细节)。 无论如何,我认为值得尝试将您的APP_PATH定义为"/urlrouter/klein"而不是"/urlrouter/klein/"。

如果这行得通,那就酷了。 如果没有,请发表评论,我会尝试重现您所看到的内容。