2012-07-12 15 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]