SlimPHP 和路由——我做错了吗?

SlimPHP and Routing - am I doing it wrong?

所以我最近,大约一天前,询问为什么我的 并根据答案,我做了适当的更改,但除非我做错了路由,否则它们不起作用.

如果我们查看我设置的路由文件,在index.php文件中需要,我们可以看到:

<?php
use \ImageUploader\Controllers as Controller;
/** ---------------------------------------------------------------- **/
// Routes.
//
// Routes are defined here. Nothing should happen in a route other then
// Calling  acontroller based action, such as: indexAction.
/** ---------------------------------------------------------------- **/
$app = new \Slim\Slim();

$app->get('/', function(){
    Controller\HomeController::showHome();
});

$app->get('/signup', function(){
    Controller\SignupController::showSignupForm();
});

$app->post('/signup/new', function() use ($app){
   var_dump($app->request()->post('username'));
   var_dump($app->request()->post('password'));
});

// Don't touch.
$app->run();

我列出了几条路线。现在我可以转到第一个,它显示 HomeController::showHome 的内容,但如果我尝试导航到 http://localhost/image-upload/signup,我会得到:

Not Found

The requested URL /image-upload/signup was not found on this server.

现在我的项目不在根目录,它在图像上传,所以当我去 localhost/image-upload 我看到 / 路由执行结果。

我的 htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /image-upload/

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
</IfModule>

我的 index.php 文件也如下所示:

<?php
/** ---------------------------------------------------------------- **/
// This is the core app.
/** ---------------------------------------------------------------- **/
if (!file_exists('bootstrap.php')) {
    throw new \Exception('Where is the bootstrap.php?');
}

require_once 'bootstrap.php';

/** ---------------------------------------------------------------- **/
// Routing.
/** ---------------------------------------------------------------- **/
require_once 'app/routes.php';

我是不是做错了 slim routing 还是...

所做的更改

修复重写基础,原定为/image-upload/。这怎么也没有解决任何问题。 Mod 重写已启用并开启。

有人建议将 image-upload/(或类似)添加到 slim 的核心路由中。这没有帮助。事实上它打破了路由。

你能试试这个吗?

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?/ [L,QSA]