我有一个具有以下结构的应用程序:
App/
|— app/
|— config
|— controllers
|— middlewares
|— routes
|— routes.php
|— views
|— app.php
|— autoload.php
|— public/
|—.htaccess
|— index.php
|— vendor/
好吧,/ public文件夹中的.htaccess中包含以下内容(来自Slim文档):
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
/ public文件夹中的index.php包含以下内容:
define('BASE_ROOT',dirname(__DIR__) . '/');
require_once BASE_ROOT.'app/app.php';
$app->run();
因此,我们转到app / app.php文件:
<?php
require BASE_ROOT.'app/autoload.php';
$app = new \Slim\App(["settings" => App\Config\Config::$config]);
$container = $app->getContainer();
$container['view'] = function($container) {
/*Set some configurations and environment vars*/
};
require BASE_ROOT.'app/routes/routes.php';
最后,在app / routes /中的route.php中:
<?php
/*Routes*/
$app->get('/hello/{name}', function (Request $request, Response $response, array $args) {
$name = $args['name'];
$response->getBody()->write("Hello, $name");
});
我把“ hello world”路由简化了,但是问题是在route.php中注册的任何路由都收到404代码...
我正在使用apache服务器,vhost上的配置如下:
<VirtualHost *:80>
DocumentRoot "C:\Users\FranciscoSalazar\Desktop\PHP-SLIM\App\public"
ServerName medo
<Directory C:\Users\FranciscoSalazar\Desktop\PHP-SLIM\App\public>
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
I use:
- PHP 7.3.2
- Slim 3.0
- Apache 2.4
如果有人知道答案或可以指导我,我将非常感谢。