这是我第一次使用Slim
,我想在别名页面中尝试使用WampServer
,我的计划是为一些应用程序制作一个Restful API
,当页面加载除Slim
之外的所有内容时,一切都很好,但当我收到一个需要加载Slim
的请求时,我得到了404 not found
错误,我认为这是.htaccess
的问题,所以我用以下代码制作了文件:
RewriteEngine On
RewriteBase /webpages/organizer 2.0/api/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
Slim
文件在api文件夹中,所以我添加了RewriteBase
,以便将来自api的每个请求重定向到index.php
,所以当我尝试另一个请求时,我得到了500 Internal Server Error
我不知道是什么导致了这种情况,因为我正在为另一个具有Yii
框架的应用程序使用相同的规则,而且它运行良好,即使我删除了这个.htaccess
文件并重试,但这次请求特定的文件,我仍然得到404 not found
,但Slim
模板错误
index.php
<?php
require('../vendor/autoload.php');
$app = new 'Slim'Slim();
$app->get('/test/:word', function($word){
echo $word;
});
$app->run();
文件夹结构:
organizer 2.0 {
vendor: {
autoload.php,
Slim: {
...
}
},
api: {
.htaccess,
index.php
},
bower_components: {
...
},
index.php
}
注意:在没有.htaccess
的情况下,我尝试访问localhost/webpages/organizer 2.0/api/index.php/test/hello
,并从slim获得404错误,但在.htaccess
尝试请求的情况下localhost/webpages/organizer 2.0/api/test/hello
返回内部错误
经过数小时的代码更改、卸载和重新安装,我发现问题出现在.htaccess
中,看起来RewriteBase
中的文件夹名称中有空间,因此我将根文件夹重命名为webpages/organizer2.0/api