【发布时间】:2015-07-04 09:34:03
【问题描述】:
这是我第一次使用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 返回内部错误
【问题讨论】:
标签: php apache .htaccess mod-rewrite slim