我在我的计算机上处理了一个个人项目,它在这台计算机的 localhost 上运行良好。但是我尝试使用我的 Raspberry Pi 作为 Web 服务器将它放到网上,但它不起作用(它显示 404 错误)。这是一个使用 PHP AltoRouter 的项目。我注意到在我的计算机上,$_SERVER['BASE-URI'] 返回 'localhost' 之后的 url,但在我的 RaspberryPi 上,它返回 'NULL'。
在公用文件夹中,我的 index.php 文件开始如下:
<?php
require '../vendor/autoload.php';
require '../app/Controllers/MainController.php';
require '../app/Controllers/LevelController.php';
$pageToDisplay = '/';
// thanks to the htaccess redirection, no querystring can be seen in the url. Htaccess will add the information about the requested page
if (isset($_GET['_url'])) {
$pageToDisplay = $_GET['_url'];
}
$router = new AltoRouter();
// we indicate to AltoRouter where the root of the site is with basePath
$router->setBasePath($_SERVER['BASE_URI']);
我的 Htaccess 文件是这样的:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
有谁知道这个问题可能来自哪里?当我将我的 Rpi 设置为 Web 服务器时,我安装了 Apache2、PHP、MySQL、PHPMyAdmin、Git、VS Code、Composer(我还编写了命令“composer install”和“composer dump-autoload”)。设置 Raspberry Pi 时有什么我忘记做的吗?
感谢您的时间 !