对API REST的GET请求始终返回index.php文件

时间:2015-05-29 10:21:32

标签: php .htaccess rest slim

我正在使用Slim开发REST api。当我在localhost中使用我的api时,一切都运行良好,但是当我尝试在我的服务器上使用它时,它不能很好地工作,返回index.php的内容。

对于这个问题,我将使用Slim框架的示例应用程序。所以我的index.php是:

<?php
require 'Slim/Slim.php';
\Slim\Slim::registerAutoloader();

$app = new \Slim\Slim();

$app->get('/hello/:name', function ($name) {
    echo "Hello, $name";
});

$app->run();
?>

我的文件夹结构是:

/var/www/html/vendor/rest/
                        libs/
                            Slim
                        v1/
                            .htaccess
                            index.php

.htaccess文件是:

AddType x-mapp-php6 .php
AddHandler x-mapp-php6 .php

Options -Indexes 
Options -MultiViews 
Options +FollowSymLinks
Options +Includes

RewriteEngine on
RewriteBase /vendor/rest/v1

RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d  
RewriteCond %{REQUEST_FILENAME} !-l  

RewriteRule ^(.*)$ %{ENV:BASE}index.php [QSA,L]

所以,当我写Postman(例如)

http://www.mydomain.es/vendor/rest/v1/hello/jose

我明白了:

Postman result

何时返回

Hello, jose

我已经过了几天而且我无法解决这个问题。怎么了?也许是.htaccess?

1 个答案:

答案 0 :(得分:0)

最后我解决了我的问题。我用这三行更改了.htaccess文件:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f  
RewriteRule ^ index.php [QSA,L]

现在一切正常。