【发布时间】:2013-08-13 19:19:56
【问题描述】:
这是我第一次使用 Slim 框架,到目前为止,我非常喜欢该应用程序的外观和感觉。使它几乎像一个快速 API 服务器。
我在我的本地机器上构建了一个小型服务器,它与虚拟主机一起工作非常好。
这与我在本地设置的虚拟主机有关,但我试图用 .htaccess 文件绕过它。
在生产服务器上,如果我输入 http://www.domain.com/public/resource,它确实可以工作。
我的目录结构如下:
public/
index.php
.htaccess
src/
.htaccess
根文件夹中的 .htaccess 如下所示:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
公用文件夹中的 .htaccess 如下所示:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
我还将发布我的 index.php 的一部分并显示到目前为止我登录的位置。
$app = new Slim\Slim();
$env = $app->environment();
switch($env['REMOTE_ADDR']) {
case '127.0.0.1':
define('ENVIRONMENT', 'local');
break;
default:
define('ENVIRONMENT', 'production');
break;
}
// Here a log works when you go to http://www.domain.com
// Get
$app->get('/:resource(/(:id)(/))', function($resource, $id = null) {
// Here it works on local machine on production there's no possible way to get here
// var_dump('foobar');die; will respond nothing to cURL -i -X GET http://www.domain.com/resource
// The request will return a 404 error
$resource = \App\Resource::load($resource);
if ($resource === null) {
\App\Resource::response(\App\Resource::STATUS_NOT_FOUND);
} else {
$resource->get($id);
}
});
【问题讨论】:
标签: php routing production-environment slim