在VPS上使用Slim Framework托管PHP应用程序的问题

时间:2016-07-05 12:15:08

标签: php .htaccess vps

我有一个使用Slim框架的PHP应用程序。在本地主机上一切正常......但是......不在VPS上......我正在使用Digital Ocean。

这是我的项目结构....只是想确保它是否正确。

ROOT DIRECTORY - app

- admin - index.php(主应用主页)             - .htaccess

- 其他CSS&的javaScript

  • API(这是超薄项目) - 包括 - lib - v1
    • .htaccess(Slim的htaccess) - index.html

主要问题:

在运行应用程序...说登录页面...它向Slim发出请求... api用json回复...但它显示在浏览器中而不是显示html格式的响应。

不确定缺少什么。 .htaccess for Slim

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ %{ENV:BASE}index.php [QSA,L]

.htaccess for main app

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L] 

</IfModule>

1 个答案:

答案 0 :(得分:0)

您是否将内容类型更改为application / json? 检查this,Slim有一种简单的方法来返回json,这样:

    $data = array('name' => 'Bob', 'age' => 40);
    $newResponse = $oldResponse->withJson($data);