.htaccess slim php请求的URL未找到

2jcobegt  于 9个月前  发布在  PHP
关注(0)|答案(1)|浏览(81)

我是相当新的超薄php,我有一个小问题,但我似乎找不到它,错误是来自xampp这是奇怪的。如果我导航到localhost/db_API/hello,它可以工作,但是当我添加args时,它就不工作了。
x1c 0d1x的数据
composer.json:

{
    "require": {
        "slim/slim": "4.*",
        "slim/psr7": "^1.6",
        "nyholm/psr7": "^1.8",
        "nyholm/psr7-server": "^1.0",
        "guzzlehttp/psr7": "^2",
        "laminas/laminas-diactoros": "^3.1"
    }
}

字符串
.htaccess公开:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]


src中的.htaccess:

RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]


db_API根目录下的.htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^$ src/ [L]
    RewriteRule (^[^/]*$) src/$1 [L]
 </IfModule>


index.php

<?php
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;

require __DIR__ . '/../vendor/autoload.php';

$app = AppFactory::create();
$app->setBasePath('/db_api');

$app->get('/hello', function (Request $request, Response $response, $args) {
    $response->getBody()->write("Hello world!");
    return $response;
});

$app->get('/hello/{name}', function (Request $request, Response $response, $args) {
    $name = $args['name'];
    $response->getBody()->write("Hello, $name");
    return $response;
});
$app->run();


先谢谢你

fnvucqvd

fnvucqvd1#

您只需要2个.htaccess文件。
1.删除项目根目录中的当前.htaccess
1.将文件src/.htaccess移动到项目根目录
1.将index.php文件移动到public/index.php

相关问题