[英]Restler 404 error Routes.php:431 with xampp
I am trying to set up a development environment on Windows with xampp 5.6.23. 我正在尝试使用xampp 5.6.23在Windows上设置开发环境。
I have an API I want to set up with Restler 3.0.0 so that I can browse to http://localhost/api/cars/search?term=red
to call the search($term)
function in the C:\\xampp\\htdocs\\api\\cars.php
file: 我有一个要与Restler 3.0.0一起设置的API,以便可以浏览到http://localhost/api/cars/search?term=red
来调用C:\\xampp\\htdocs\\api\\cars.php
的search($term)
函数C:\\xampp\\htdocs\\api\\cars.php
文件:
<?php
class cars{
public function search($term) {
// do search...
return $result;
}
}
I also have a C:\\xampp\\htdocs\\api\\index.php
set up with: 我也有一个C:\\xampp\\htdocs\\api\\index.php
设置为:
<?php
require_once 'vendor/autoload.php';
require_once 'vendor/luracast/restler/vendor/restler.php';
use Luracast\Restler\Restler;
Defaults::$crossOriginResourceSharing = true;
$r = new Luracast\Restler\Restler();
$r->setCompatibilityMode('2');
$r->setSupportedFormats('JsonFormat', 'XmlFormat', 'JsFormat');
Luracast\Restler\Format\JsonFormat::$unEscapedUnicode = false;
$r->addAPIClass('cars');
$r->addAPIClass('Luracast\\Restler\\Resources');
$r->handle(); //serve the response
and C:\\xampp\\htdocs\\api\\.htdocs
: 和C:\\xampp\\htdocs\\api\\.htdocs
:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} ^$
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>
But if I go to any URL ( /
or /cars
) I get a 404 error: 但是,如果我转到任何URL( /
或/cars
),都会收到404错误:
<response>
<error>
<code>404</code>
<message>Not Found</message>
</error>
<debug>
<source>Routes.php:431 at route stage</source>
<stages>
<success>get</success>
<failure>route</failure>
<failure>negotiate</failure>
<failure>message</failure>
</stages>
</debug>
</response>
I have tried multiple answers from SO but none have worked in my instance. 我尝试了SO的多个答案,但没有一个在我的实例中起作用。 I have uncommented LoadModule rewrite_module modules/mod_rewrite.so
and set AllowOverride All
everywhere I could find it in httpd.conf
. 我没有对LoadModule rewrite_module modules/mod_rewrite.so
进行注释,并在httpd.conf
可以找到的AllowOverride All
地方设置AllowOverride All
。 I have also tried moving my everything to htdocs
instead of a sub folder but still get the same result. 我也尝试将所有内容移至htdocs
而不是子文件夹,但仍得到相同的结果。
Since you don't have an index()
function but only a search()
function in your class cars
, you need to access the URL /cars/search/term
. 由于类cars
没有index()
函数,而只有search()
函数,因此需要访问URL /cars/search/term
。
Or are you trying to achieve something else? 还是您正在尝试实现其他目标?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.