2012-07-12 48 views
3

我正在使用Apache 2.2和PHP 5.3。我正在嘗試使用Fatfree框架進行路由。我的index.php文件看起來像:在Apache 2.2上使用FatFree和PHP5.3時無法呈現簡單頁面

<?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://本地主機:8080 /」它正確地呈現文件模板/ 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://本地主機: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 /「基礎是由於另一個答案這個問題有類似的問題。

我也試圖與以下的.htaccess:

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

您是否啓用了mod_rewrite並設置了規則(即在.htaccess文件中)? – madflow 2012-07-12 19:22:42

+0

我添加了更多信息。謝謝。 – Tony 2012-07-12 19:39:43

+0

那麼你在哪裏index.php?在DocumentRoot/fatfree中還是在文檔根目錄中? – madflow 2012-07-12 19:47:13

回答

2

你真的需要看看你的服務器日誌。如果你沒有啓用它們,我會建議你這樣做。 Apache有非常好的日誌。如果您看到日誌條目並且沒有收到500服務器錯誤,那麼通常不是mod_rewrite。

如果你想確保重寫模塊被加載(在Linux上),試試這個:

[[email protected] ~]# httpd -M 2>&1|grep rewrite

它會返回一些東西給這個效果:

rewrite_module (shared)

+0

謝謝!我在httpd.conf中使用了wamp並且只是取消了註釋mod_rewrite.so – mdanishs 2015-04-02 16:46:39

0

有config.ini文件在fatfree

[globals] 
DEBUG=3 
UI=ui/ 

DEBUG的根文件= 3會讓F3顯示所有錯誤從內部,並改變用戶界面值爲i因爲您需要將您的模板保存在ui文件夾中,所以在此配置中您必須將其更改爲您自己的模板目錄。

根據f3文檔,靜態調用約定(F3 :: xxx)已被棄用,更好的選項是調用F3的一個實例(如$ f3-> xxx)。

還請認真檢查isuues相關的mod_rewrite和.htaccess的HTTPD錯誤日誌。

-

0

您只需要在您的索引中。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/ 

routes.ini:

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

基本控制器渲染視圖:

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

我曾經有和你一樣的問題。

我在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。

0

啓用重寫引擎,並請求路由到框架

嘗試此,此修復程序爲我工作。修改您的.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]