GET 请求 API REST 总是 return index.php 文件
GET request to an API REST always return the index.php file
我正在使用 Slim 开发 REST api。当我在 localhost 中使用我的 api 时一切正常,但是当我尝试在我的服务器上使用它时它不能正常工作,returning index.php.[= 的内容19=]
对于这个问题,我将使用 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
我得到:
什么时候应该 return
Hello, jose
这几天都没有解决这个问题。怎么了?也许是 .htaccess?
终于解决了我的问题。我用这三行更改了 .htaccess 文件:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
现在一切正常。
我正在使用 Slim 开发 REST api。当我在 localhost 中使用我的 api 时一切正常,但是当我尝试在我的服务器上使用它时它不能正常工作,returning index.php.[= 的内容19=]
对于这个问题,我将使用 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
我得到:
什么时候应该 return
Hello, jose
这几天都没有解决这个问题。怎么了?也许是 .htaccess?
终于解决了我的问题。我用这三行更改了 .htaccess 文件:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
现在一切正常。