【发布时间】:2020-02-09 02:02:44
【问题描述】:
我有这个代码在linux上使用slim框架和php和apache2:
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require '../../vendor/autoload.php';
$app = new \Slim\App;
#doesn't work results in URl not found in browser
$app->get('/hello','sayhi');
#works, when i just type in 'localhost/' into my webbrowser
$app->get('/',function()
{
return 'testing';
});
$app->run();
#functions
function sayhi()
{
echo 'hello world again';
}
.htaccess(与我的 index.php 文件相同的目录)
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
000-default.conf 将 documentroot 设置为我的 php 文件和 .htaccess 文件所在的目录。
当我在我的网络浏览器中输入“localhost/”时,会执行匿名函数。因为如果服务器收到 '/' 就会这样做
但是当我输入'localhost/hello'时会导致找不到URL,当它应该在服务器接收到这种类型的url时执行'sayhi'函数。
为什么要这样做?我的代码有问题吗,因为我不明白如何进行排序。
我也尝试将选项设置为我的 php 文件的目录
允许全部覆盖
但是,当我设置此选项时,这会导致 500 内部错误。我尝试遵循本指南:500 internal error guide 无济于事。
我不知道如何排序,帮助?
【问题讨论】:
-
您使用的是哪个版本的 os Slim?它看起来像 slim 3,但你的应用程序实例很奇怪(slim 3 需要提供配置)
-
我使用的是 Slim 3.12 版本
-
.htaccess文件的内容是什么?这个文件存在吗? -
是的,我已经更新了我的问题并将其包含在问题描述中。
-
@Entilore 我有 3.12 并按照 slim 版本 3 的代码示例,与网站的实现风格完全相同:slimframework.com/docs/v3/tutorial/first-app.html
标签: php apache slim ubuntu-18.04