我正在尝试使用php fat free framework(又名F3 )来快速构建Web应用程序。
理论上(从阅读文档),它应该是一个轻而易举(即简单),但是,我已经困在一个问题好几天了,从堆栈溢出这里的类似问题判断,似乎我不是唯一一个在这个问题上挣扎的人。
以下是重要事实:
这就是麻烦开始的地方。当我导航到http / fatfree-master时,我得到的错误就是这个问题的标题;即:
未找到
HTTP 404(GET /)C:/wamp/www/fatfree-master/index.php:111 Base-> run()
我的index.php看起来像这样:
<?php // <- surprisingly, I had to add this line to the index.php example provided by F3, was this an oversight or a deliberate design feature?
$f3=require('lib/base.php');
$f3->set('DEBUG',3);
$f3->set('UI','ui/');
....
// custom PHP code defining routes etc ...
....
$f3->run(); // barfs here
现在,我是第一个承认,我不理解Apache重写的神秘语法,因此我保留了我的.htaccess文件(当我下载F3时)。
以下是我的.htaccess(F3提供的默认文件)的内容:
# Enable rewrite engine and route requests to framework
RewriteEngine On
# Some servers require you to specify the `RewriteBase` directive
# In such cases, it should be the path (relative to the document root)
# containing this .htaccess file
#
# RewriteBase /
RewriteRule ^(tmp)\/|\.ini$ - [R=404]
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L,QSA]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
任何人都可以向我解释一下,为什么我会收到404错误,以及如何修复它?
[[附加说明]]
我的(编辑过的)index.php文件中有两条路由。我的index.php现在看起来像这样:
<?php
$f3=require('lib/base.php');
$f3->set('AUTOLOAD','app/controllers/');
$f3->set('DEBUG',3);
$f3->set('UI','ui/');
/* Tools */
$f3->route('GET @tools_calculator_dates: /tools/calculator/dates', 'Beer->list');
// Default route
$f3->route('GET /',
function() {
echo 'Hello, world!';
}
);
$f3->run();
当我在浏览器中访问/时,我得到“Hello,world!” (如预期的那样) 当我在浏览器中访问/ tools / calculator / dates时,出现以下错误:
未找到
HTTP 404(GET / tools / calculator / dates)
•C:/wamp/www/fatfree-master/index.php:119 Base-&gt; run()
现在,我在这里有一个课程:/path/to/wamp/www/fatfree-master/app/controllers/beer.php
该课程的内容是:
<?php_
class Beer
{
function list() {
echo "Beer::list() called!";
}
}
为什么我收到404错误?
答案 0 :(得分:0)
你得到的错误不是来自Apache,而是来自F3。
如果您未指定路线GET /
,F3将抛出404。
答案 1 :(得分:0)
404错误可能是由以下原因之一引起的:
RewriteBase
关于第1点,有关路线声明的详情,请参阅the documentation。
关于第2点,如果您在设置框架的自动加载器(answer变量)时遇到问题,请查看此AUTOLOAD。
关于第3点:RewriteBase
在子文件夹中运行时通常是可选的,但在特定情况下(例如,当启用mod_userdir时),需要明确设置它。
因此,在您的情况下,您可以尝试在。{1}}之后的.htaccess文件中添加以下指令:
RewriteEngine On