Restler 404 Error

283 views Asked by At

i have just started to create an api with Restler and have the follwoing code.

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

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

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. When i open localhost/api/ in the browser it will show Version 1.0 as expected. But when i open info or getList i get a 404 error from apache.

How can i fix it? Many thanks for your help

1

There are 1 answers

0
Mikhail On

You should add this to your /api/.htaccess file:

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>