簡體   English   中英

PHP Slim REST Framework,.404 未找到錯誤

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM