【问题标题】:Restler always returns not foundRestler 总是返回未找到
【发布时间】:2012-09-01 16:18:59
【问题描述】:

我被困在这里,在 wamp 中我运行一切并且工作正常,但是,当我尝试在 centos 盒子中安装我的 api 时,我总是收到“未找到”错误。

我不知道还能做什么!

即使是 say/hello 示例也失败了...

是否有任何关于处理 restler 的 apache 要求规范?

有什么想法吗?有点急

say.php:

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

index.php

<?php
    require_once 'restler/restler.php';
    require_once 'say.php';

    $r = new Restler();
    $r->addAPIClass('Say');

    $r->setSupportedFormats('jsonpformat', 'jsonformat', 'xmlformat', 'yamlformat');
    $r->handle();

.htaccess

DirectoryIndex index.php
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^$ index.php [QSA,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
<IfModule mod_php5.c>
    php_flag display_errors On
</IfModule>

错误:

未找到 在此服务器上找不到请求的 URL /mylocation/say/hello。

这基本上是我所有的代码,如果你们认为 jsonpformat 可能会妨碍我,我可以将代码粘贴在这里。

当我像这样输入网址时:http://myhost/mylocation/ 我收到一个 json 错误:

{
  "error": {
    "code": 404,
    "message": "Not Found"
  }
}

如果我输入 http://myhost/mylocation/say/hello 然后我得到 not found 错误,就像 .htaccess 不起作用。

[编辑]

如果我像这样将“index.php”添加到 url 中似乎可以工作:http://myhost/mylocation/index.php/say/hello,但我不能像这样离开它......

我来自:Restler returns 404 status code if index.php is not included in URL

【问题讨论】:

  • 如果很紧急,您应该告诉我们更多细节
  • 我已经完成了对问题的改进,但是,我真的可以使用一些关于 apache 和 php 的 restler 要求的信息,以防我在安装中错过了一些模块或扩展。
  • 您的.htaccess 文件似乎没问题,所以您的mod_rewrite - check if it's installed 可能有问题。
  • 事实上@moonwave99 我不得不将 httpd.conf 文件的 de AllowOverride 变量设置为 All 而不是 None

标签: php web-services api rest restler


【解决方案1】:

好的,我找到了问题,谢谢大家的帮助。

解决方案是将httpd.conf 文件的AllowOverride 变量设置为All 而不是None。一旦我尝试它就可以了:)

除了apache的mod_rewrite之外,我没有找到运行restler的其他要求,如果有,我会编辑并放在这里。

我发现这是 restler 的常见问题,最好在文档中提及它,希望对您有所帮助。

PD:我必须说,在我发布问题后一分钟都没有过,在编辑我的问题时被否决是非常烦人的,但是我尽可能快地做到了。你可能会说“你为什么要发布它呢?”由于restler需求部分,它不需要太多细节来回答......

【讨论】:

  • 优秀。这绝对应该在 Restler 的“入门”部分明确说明。谢谢丹尼尔。
猜你喜欢
  • 2013-12-27
  • 1970-01-01
  • 2012-08-16
  • 2020-03-25
  • 1970-01-01
  • 2018-10-10
  • 2020-12-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多