[英]PHP Slim REST Framework, .404 not found error
我正在尝试使用 Slim 框架。 并发现了奇怪的行为。
<?php
error_reporting(-1);
ini_set('display_errors', 'On');
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require '../../vendor/autoload.php';
require_once '../include/db_handler.php';
$app = new \Slim\App;
$app->get('/', function (Request $request, Response $response) {
$response->getBody()->write("Hello, api v1");
return $response;
});
$app->get('/chat', function (Request $request, Response $response) {
$response->getBody()->write("Hello, chat");
return $response;
});
$app->run();
?>
那么如果我指向
http://some.ip.address/v1/
我得到
Hello, api v1
如果指向
http://some.ip.address/v1/chat
我收到 404 not found 错误。
为什么??
30 秒后,我发布了问题。 我找到了这个问题的答案。
http://www.slimframework.com/docs/v3/tutorial/first-app.html
你需要.htaccess
文件。
现在您已经更改了配置,请不要忘记重新启动您的服务器进程!
我的 src/public 目录中也有一个 .htaccess 文件; 这依赖于启用 Apache 的重写模块,并简单地将所有 Web 请求发送到 index.php,以便 Slim 可以为我们处理所有路由。 这是我的 .htaccess 文件:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.