doulu6234
2015-06-16 05:27
浏览 10
已采纳

Klein url路由器无法在XAMPP上运行

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

I installed the klein router using composer.
And, I use this script just for simple basic routing

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);

And I also have this .htaccess

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

But, when I go to http://localhost/urlrouter/klein/hello , it redirects me to the XAMPP homepage or http://localhost/xampp/splash.php
I can't figure out what's wrong with this router. Please help me

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • du12197 2015-06-17 14:47
    最佳回答

    I've never tried to manipulate the REQUEST_URI with Klein (not saying you shouldn't, just warning of a lack of expertise), but your substr() call is going to yield "hello", where your route pattern is "/hello". That might or might not matter (the route matching logic in Klein is somewhat complex, and I haven't internalized all its details). At any rate, I think it's worth a try to define your APP_PATH as '/urlrouter/klein' instead of '/urlrouter/klein/'.

    If that works, cool. If not, post a comment and I'll try to reproduce what you're seeing.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题