gpt4 book ai didi

php - 路由不适用于 Slim 框架

转载 作者:可可西里 更新时间:2023-10-31 23:45:10 26 4
gpt4 key购买 nike

我正在学习 slim 框架。我有一点必须设置我的网络服务器,这样我才能看到类似 http://slimapp 的内容。而不是 http://localhost/slimapp/public/index.php .

我像这样在项目的公共(public)文件夹中包含了一个 .htaccess 文件

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

我还在我的wamp服务器上设置了一个虚拟主机

<VirtualHost *:80>
DocumentRoot "C:\wamp64\www\slimapp\public"
ServerName slimapp

<Directory "C:\wamp64\www\slimapp\public">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

我也把这个添加到我的主机文件中

127.0.0.1 slimapp 

我重新启动了我的服务器,但当我尝试访问我的路由时出现“未找到”错误。

"Not Found
The requested URL /hello/uche was not found on this server."

这是我的 index.php 文件

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

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

$app = new \Slim\App;
$app->get('/hello/{name}', function (Request $request, Response $response) {
$name = $request->getAttribute('name');
$response->getBody()->write("Hello, $name");

return $response;
});
$app->run();

请帮帮我。

最佳答案

尝试将.htaccess 文件移动到根目录

关于php - 路由不适用于 Slim 框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45385196/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com