我是相当新的超薄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();
型
先谢谢你
1条答案
按热度按时间fnvucqvd1#
您只需要2个
.htaccess
文件。1.删除项目根目录中的当前
.htaccess
1.将文件
src/.htaccess
移动到项目根目录1.将index.php文件移动到
public/index.php