当我访问http://slim.com:8080/parkingmeter/v1/account/test
时,我需要配置nginx重写以指向account/index.php
或admin/index.php
。如何配置?
http://slim.com:8080/parkingmeter/v1/account/test
root /usr/local/nginx/html/slim/www;
重写^ / parkingmeter / v1 /([[a-z] +)/(。*)$ /$1/index.php?$2;
index.php内容如下
<?php
Use \Psr\Http\Message\ServerRequestInterface as Request;
Use \Psr\Http\Message\ResponseInterface as Response;
Require '../../vendor/autoload.php'; //require_once __FILE__."/../../../model/UserModel.class.php";
$config = [
'settings' => [
'displayErrorDetails' => true,
] ]; $app = new \Slim\App($config);
$app->get('/test', function($request, $response, $args){ Return $response->write("Hello, Slim!"); });
// $app->get('/hello/{name}', function (Request $request, Response $response, array $args) { // $name = $args['name']; // $response->getBody()->write("Hello, $name");
// return $response; // });
//routing //require_once dirname(__FILE__)."/../../routes/routes.php";
$app->run();
完成上述配置后,浏览器不会输出Hello,Slim!