我的应用程序位于C:\ xampp \ htdocs \ urlrouter \ klein \
我使用作曲器安装了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
我无法弄清楚此路由器出了什么问题。请帮我
我从来没有尝试过REQUEST_URI
使用Klein来操作(不是说您不应该,只是警告您缺乏专业知识),但是您的substr()调用将产生“ hello”,而您的路由模式为“ / hello” 。这可能或可能不重要(Klein中的路由匹配逻辑有些复杂,我还没有内部化所有细节)。无论如何,我认为值得将您定义APP_PATH
为“ / urlrouter / klein”而不是“ / urlrouter / klein /”。
如果可行,请冷静。如果没有,发表评论,我会尝试重现您所看到的内容。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句