我正在关注FatFree框架,但是我正处于第一道障碍。
我在Windows10上运行Apache,php5.6
我在我的'vendor'目录中安装了无胖发行版,该目录位于我的服务器根目录下面。同样在根目录下面我创建了一个新的项目目录'NewProject',并在其中放入以下index.php
<?php
define ('F3LIB','../vendor/FatFree/lib');
$f3 = require (F3LIB.'/base.php');
$f3->route('GET /',
function() {
echo 'Hello, world!';
}
);
$f3->run();
当我在浏览器中输入/localhost/NewProject
时,我得到:HTTP 404(GET /index.php)
我尝试过像GET /NewProject
这样的事情,但结果没有区别。研究表明我可能需要一个变体.htaccess
文件 - 我尝试了一两个想法但没有成功。如果需要,我需要将哪个目录放入?
我试过这个.htaccess文件:
# 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 NewProject
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]
就.htaccess文件的内容而言,我是一个完整的新手,我从来没有在我的项目中需要一个。我从与类似问题相关的答案中提取了文本。
答案 0 :(得分:0)
如果将来它应该帮助别人,我现在可以确认我找到了问题的真正原因。根据上述评论,我发现我已经开始使用基本的“hello world”,但尝试到达其他路线“/ about”等仍然失败。
经过进一步研究后,我发现,除了激活Appache http.conf中的mod_dir模块之外,还必须确保通过在Directory Document部分的Directory部分中设置“AllowOverride All”来允许mods,否则.htaccess文件无效。这是我没有做到的事情,之后一切都很顺利。事实上,在这之后,我似乎不需要RewriteBase行。
另外值得注意的是内置的php5服务器看起来不需要特殊设置,只需用“php -S localhost:PORT -t YourDocumentRootPath”启动吧