【问题标题】:Routes not working on Slim framework路由不适用于 Slim 框架
【发布时间】:2018-01-05 05:08:27
【问题描述】:

我正在学习苗条的框架。我有一点需要设置我的网络服务器,这样我才能看到类似 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();

请帮帮我。

【问题讨论】:

标签: php .htaccess slim


【解决方案1】:

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

【讨论】:

【解决方案2】:

如果有人仍然遇到这个问题,我就是这样解决的:

启用模型重写。在您的终端类型中:

sudo a2enmod rewrite && sudo service apache2 restart

http://help.slimframework.com/discussions/problems/10216-beginner-routes-not-working

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-27
    • 1970-01-01
    • 1970-01-01
    • 2017-10-13
    • 1970-01-01
    • 1970-01-01
    • 2018-03-08
    • 2016-06-28
    相关资源
    最近更新 更多