在 Apache 2.2 上使用 FatFree 和 PHP5.3 时无法呈现简单页面


Can't render a simple page when using FatFree and PHP5.3 on Apache 2.2

我正在使用Apache 2.2和PHP 5.3。我正在尝试使用Fatfree框架进行路由。我的索引.php文件如下所示:

<?php
require_once 'f3/lib/base.php';
F3::route('GET /','home');
function home() {
    echo F3::render('templates/index.html');
}
F3::route('GET /@pagenum','mainlist');
function mainlist() {
    F3::set('pagenum', @pagenum);
    echo Template::serve('templates/index.html');       
}
F3::run();
?>

如果我转到"http://localhost:8080/",它会正确呈现文件 templates/index.html,这意味着PHP和Fatfree正在工作。但是如果我去"http://localhost:8080/1",那么它不起作用。我收到以下错误:

Not Found
The requested URL /1 was not found on this server.

如果我将第一部分更改为

F3::route('GET /anotherthing','home');
function home() {
    echo F3::render('templates/index.html');
}

那么"http://localhost:8080/anotherthing"也不起作用。它只在根上工作。有什么帮助吗?

更多信息这是在 httpd.conf 中配置

DocumentRoot "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs"
<Directory "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs">
Options -Indexes FollowSymLinks Includes
AllowOverride All
Order allow,deny
Allow from All
</Directory>

Modrewrite已启用:

LoadModule rewrite_module modules/mod_rewrite.so

.htaccess看起来像:

RewriteEngine On
RewriteBase /fatfree/
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /fatfree/index.php [L,QSA]

"/fatfree/"基础是由于另一个具有类似问题的SO问题的答案。

我还尝试使用以下.htaccess:

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

您确实需要查看服务器日志。如果您尚未启用它们,我建议您这样做。Apache有非常好的日志。如果您看到日志条目并且没有收到 500 服务器错误,则通常不会mod_rewrite。

如果你想确保重写模块被加载(在 Linux 上(,试试这个:

[root@server ~]# httpd -M 2>&1|grep rewrite

它将返回一些内容:

rewrite_module(共享(

启用重写引擎并将请求路由到框架

试试这个,这个修复程序对我有用。 修改了您的 .htaccess 文件,就像下面的代码一样。

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 ^(lib|tmp)'/|'.(ini|php)$ - [R=404]
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [END,QSA]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

你可以试试这个.htaccess:

RewriteEngine On
RewriteRule ^(app|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]

fatfree 根目录中有 config.ini 文件

[globals]
DEBUG=3
UI=ui/

DEBUG=3 将让 f3 显示来自内部的所有错误,并且更改 UI 值很重要,因为您需要将模板保存在 ui 文件夹中,因此在此配置中,您必须将其更改为您自己的模板目录。

根据 f3 文档,静态调用约定 (F3::xxx( 已被弃用,更好的选择是调用 F3 的实例(如 $f 3->xxx(。

还请检查HTTPD错误日志中与mod_rewrite和.htaccess相关的isuues。

--

你只需要在你的索引中.php

$f3=require('lib/base.php');
$f3->config('config/config.ini');
$f3->config('config/routes.ini');
$f3->run();

然后在您的配置中.ini :

[globals]
DEBUG=3
UI=views/

路线.ini :

[routes]
GET /=ControllerName->methodThatRenderTheView
GET /@pagenum=ControllerName->methodThatRenderTheView

渲染视图的基本控制器:

class ControllerName {
   public function methodThatRenderTheView() {
      $this->f3->set('view', 'template.htm');
   }
}

我曾经和你有同样的问题。

我在 httpd.conf 条目中的 DocumentRoot 看起来像:

<Directory />
    AllowOverride none
    Require all denied
</Directory>

使用这些 .htaccess 指令:

RewriteEngine On
RewriteBase /fatfree/
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /fatfree/index.php [L,QSA]

mod_rewrite夫妇在我这边工作正常。截至今天,我有最新的 f3 和 wamp。