我犯了这个错误

我一整天都在寻找解决方案,包括试图像这里所说的那样设置适当的目录,还包括所需的两个.htaccess文件,但是没有任何效果。
https://github.com/selective-php/basepath#installation
这是我的index.php
<?php
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Selective\BasePath\BasePathMiddleware;
use Psr\Http\Message\ResponseInterface;
use Slim\Exception\HttpNotFoundException;
use Slim\Factory\AppFactory;
use Selective\BasePath\BasePathDetector;
require_once __DIR__ . '/../vendor/autoload.php';
$app = AppFactory::create();
// Add Slim routing middleware
$app->addRoutingMiddleware();
// Set the base path to run the app in a subdirectory.
// This path is used in urlFor().
/* setting this full path was a solution provided by another user here
https://stackoverflow.com/a/61677171/6791921
but doesn´t work for me */
$app->setBasePath("/02.rest-slim-test/public/index.php");
$app->addErrorMiddleware(true, true, true);
// Define app routes
$app->get('/', function (Request $request, Response $response) {
$response->getBody()->write("Hello, world!");
return $response;
});
// Run app
$app->run();
?>此外,我还将分享我的项目框架和2 .htaccess,以及我的composer.json。

公用/文件夹上的.htaccess:
# Redirect to front controller
RewriteEngine On
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]我的项目根目录上的.htaccess:
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]composer.json
{
"require": {
"slim/slim": "4.*",
"slim/psr7": "^1.4",
"selective/basepath": "^2.0"
}
}我使用XAMPP时:
Apache/2.4.47 (Win64) OpenSSL/1.1.1k PHP/8.0.5
如phpinfo()所述,加载的模块

如phpinfo()所述,启用了mod_rewrite模块
此外,我还试图更改apache httpd.conf指令,但没有任何效果,因为我在某个地方见过,但不起作用。
现在是这样了。在剩下的项目中,我没有问题。
<Directory />
AllowOverride none
Require all denied
</Directory>我不知道我能说什么更相关的信息。
我看过的其他资源:
PHP Slim4 on Apache2 gives HttpNotFoundException
发布于 2021-05-28 20:51:33
好的,我设法解决了,这是有效的代码。主要的更改是在SetBasePath()上的path参数上--尽管我以前尝试过同样的方法,但现在它起作用了。以防万一对某人有用。
<?php
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Selective\BasePath\BasePathMiddleware;
use Psr\Http\Message\ResponseInterface;
use Slim\Exception\HttpNotFoundException;
use Slim\Factory\AppFactory;
use Selective\BasePath\BasePathDetector;
require_once __DIR__ . '/../vendor/autoload.php';
$app = AppFactory::create();
// Add Slim routing middleware
$app->addRoutingMiddleware();
$app->setBasePath("/02.rest-slim-test/public");
$app->addErrorMiddleware(true, true, true);
// Define app routes
$app->get('/', function (Request $request, Response $response) {
$response->getBody()->write("Hello, world!");
return $response;
});
// Run app
$app->run();
?>https://stackoverflow.com/questions/67743604
复制相似问题