.htaccess 路由在Slim框架上不起作用

js4nwp54  于 2023-05-07  发布在  其他
关注(0)|答案(2)|浏览(187)

我正在学习Slim框架。我得到了一个点,我必须设置我的web服务器,这样我就可以看到像http://slimapp而不是http://localhost/slimapp/public/index.php
我在项目的公用文件夹中包含了一个.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();

请帮帮我。

qlvxas9a

qlvxas9a1#

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

rslzwgfq

rslzwgfq2#

如果有人仍然面临这个问题,这是我如何解决它:
启用模型重写。在您的终端类型:
sudo a2enmod rewrite && sudo service apache2 restart
http://help.slimframework.com/discussions/problems/10216-beginner-routes-not-working

相关问题