簡體   English   中英

在 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 框架進行路由。 我的 index.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 重寫

它將為此效果返回一些東西:

重寫模塊(共享)

啟用重寫引擎並將請求路由到框架

試試這個,這個修復對我有用。 修改您的 .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 的實例(如 $f3->xxx)。

還請檢查 HTTPD 錯誤日志以了解與 mod_rewrite 和 .htaccess 相關的問題。

--

你只需要在你的 index.php 中

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

然后在你的 config.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。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM