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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)