我不能让Restler工作

Bok*_*kal 0 php rest nginx

我一直在尝试使用Restler php api.

我在我的网络服务器的根目录下有一个api.php文件:

<?php
require_once('lib/restler.php');

class Say {
    function hello($to='world') {
        return "Hello $to!";
    }
}

$r = new Restler();
$r->addAPIClass('Say');
$r->handle();
?>
Run Code Online (Sandbox Code Playgroud)

我尝试使用最简单的示例GET api.php/say/hello,但是nginx继续回复我的错误404.在日志中我看到"不是目录".

我想这是我的nginx conf的一个问题,但找不到任何关于它的具体信息.任何的想法?

Bok*_*kal 5

解决我的问题:

我将我的代码放入/api/index.php

然后修改我的nginx配置添加:

location /api {
        if (!-f $request_filename) {
            rewrite ^(.*)$ /api/index.php last;
        }

        if (!-d $request_filename) {
            rewrite ^(.*)$ /api/index.php last;
        }
    }
Run Code Online (Sandbox Code Playgroud)

所以现在如果我调用GET/api/say/hello,它会重定向到/api/index.php/say/hello,重写规则允许restler完成它的魔法.

我希望这将有助于nginx上restler的未来用户.