简体   繁体   English

Restler 404错误

[英]Restler 404 Error

i have just started to create an api with Restler and have the follwoing code. 我刚刚开始使用Restler创建一个api,并具有以下代码。

index.php index.php

require_once '../vendor/restler.php';
use Luracast\Restler\Defaults;
use Luracast\Restler\Restler;
Defaults::$useUrlBasedVersioning = true;
$r = new Restler();
$r->setAPIVersion(1);
$r->setSupportedFormats('XmlFormat', 'JsonFormat');
$r->addAPIClass('Info', '');
$r->addAPIClass('Info');
$r->addAPIClass('getList');
$r->handle();

info.php info.php

<?php
class Info {
    function index() {
        return "Version 1.0.0";
    }
}
?>

v1/getList.php v1 / getList.php

<?php
namespace v1;
use stdClass;
class getList
{
    function index()
    {
        return "hello";
    }
    function newest() {
        return "hello2";
    }
}

I'm testing it with xampp on a windows machine and localhost/api/ is mapped to the public folder. 我正在Windows机器上使用xampp测试它,并且localhost / api /映射到公用文件夹。 When i open localhost/api/ in the browser it will show Version 1.0 as expected. 当我在浏览器中打开localhost / api /时,它将按预期显示版本1.0 But when i open info or getList i get a 404 error from apache. 但是当我打开infogetList时,我从apache收到404错误。

How can i fix it? 我该如何解决? Many thanks for your help 非常感谢您的帮助

You should add this to your /api/.htaccess file: 您应该将此添加到您的/api/.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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM