XAMPP 找不到服务器 404 页面

XAMPP server 404 Page Not Found

我正在尝试将 php 文件重新用于 aa 作业。 因此 index.php

中的以下行
require '.././library/Slim/Slim.php';

给我错误信息:

404 Page Not Found

The page you are looking for could not be found. Check the address bar to ensure your URL is spelled correctly. If all else fails, you can visit our homepage at the link below.

文件夹库相对文件index.php倒退了一步。 该文件存在并且我相信路径是正确的,因为当我将行更改为

require '.././library/Slim/Slim2.php'; //file Slim2.php not present

我收到的是这条错误消息

Warning: require(.././library/Slim/Slim.php2): failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/Julio/Temperature/api/index.php on line 6

Fatal error: require(): Failed opening required '.././library/Slim/Slim.php2' (include_path='.:/Applications/XAMPP/xamppfiles/lib/php') in /Applications/XAMPP/xamppfiles/htdocs/Julio/Temperature/api/index.php on line 6

怎么了? 使用 MAC

为了进一步说明我的评论,您收到的错误消息是 Slim 传递的错误消息,因为它无法识别您正在访问的端点。

例如,如果您使用以下方法创建了新的 Slim App 实例:

$app = new \Slim\App;

$app->get('/', function ($request, $response, $args) {
    // Logic for the root path here.
}

以上并不是最好的方法,你真的想将路由提取到他们自己的文件中。

完整的 Slim 文档可以在这里找到:http://www.slimframework.com/docs/

编辑:刚注意到你用的是Slim2,我上面的例子是Slim3所以有一些不同,但是你现在的404的解决方案应该是一样的。您需要创建一个路由来处理您要查看的页面,并确保您的前端控制器设置正确。

Edit2: 赶快把下面的写出来看看能不能帮到你,最近很忙没时间讲这个任何更多的细节。您还应该知道下面的示例设置是在 Slim3 中完成的,并且是 非常 基本的。将有更多优化的方法来设置文件夹结构等,但这应该给你一个起点。我建议的主要事情是研究一些 Slim 项目和 Slim 文档本身,以很好地掌握微框架的工作原理。

|- public
  |- index.php
  |- .htaccess
|- src
  |- ProjectName
    |- Routes
      |- example.php
    |- bootstrap.php
|- vendor

index.php

<?php 
// Pull in our bootstrap file.
require_once '../src/ProjectName/bootstrap.php';
$app->run();

.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME}% !-f
RewriteCond %{REQUEST_FILENAME}% !-d
RewriteRule ^ index.php [QSA,L]

bootstrap.php

<?php 
require_once '../vendor/autoload.php';
$app = new \Slim\App();
require_once 'Routes.php';

example.php

$app->get('/example/{name}', function ($request, $response, $args) {
    echo 'Hello ' . $args['name'];
}

确保 Apache 不会因为以下 Apache 配置而忽略 .htaccess 文件 AllowOverride none;检查您的虚拟主机配置和 add/amend 到 AllowOverride All:

   <Directory /var/www/site/example.com/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>