克莱因路线不会返回任何东西

时间:2013-11-28 15:36:36

标签: php .htaccess routing

我的index.php

中有这个代码
 <?php

require 'vendor/autoload.php';

$router = new \Klein\Klein();

$router->respond('/hello-world', function () {
    return 'Hello World!';
});

$router->dispatch();

和htaccess:

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

当我尝试打开/ hello-world(或index.php / hello-world)时,它只给我一个空白的白色屏幕。 如果我只有这条路线:

$router->respond(function () {
    return 'All the things';
});

它适用于index.php /但不适用于/

我找了很久但却看不出什么错?

2 个答案:

答案 0 :(得分:1)

尝试此操作并使用您的应用程序的真实路径更改/ path / to / app

 define('APP_PATH', '/path/to/app');
 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);

答案 1 :(得分:0)

看起来重写不起作用。只是尝试在没有任何框架的情况下回复一些简单的东西:

index.php (只有这三行)

<?php 
    echo 'does it work?';
?>

然后尝试调用/ hello-world之类的东西。如果它没有显示您的消息,可能您的主机不支持mod_redirect。

您应该能够使用函数apache_get_modules显示所有已激活的apache模块:

<?php
    print_r(apache_get_modules());
?>

应该列出mod_rewrite。

相关问题