The PHP REST flight service always returns & ldquo; Hello World & rdquo;

advertisements

I am trying to build a REST data service with Flight as it seems to be easy to understand but even so I cannot get the simple out-of-the-box demo working. I am running on a Windows 2008 R2 with IIS 7.5, URL Rewrite and PHP 5.4 on top.

I have imported this .htaccess file in to the IIS URL Rewrite module:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]

IIS imports it without any problems:

I then have this PHP code:

<?PHP
require 'flight/Flight.php';

Flight::route("/", function (){
    echo 'Hello World';
});

Flight::route('/blog(/@year(/@month(/@day)))', function($year, $month, $day){
    // This will match the following URLS:
    // /blog/2012/12/10
    // /blog/2012/12
    // /blog/2012
    // /blog
    echo "Blog year=[$year], month=[$month], day=[$day]<br />";
});

Flight::start();
?>

If I request http://myserver/blog/2012 or http://myserver/what/ever I always get the front page text, "Hello World".

For me it looks like the URL rewriting is working as I at least don't get a 404-error but what am I missing?


I know this is old, but here's your answer anyways.

There is no problem in your code, this is an .htaccess on IIS problem. Try importing only these 2 lines:

Replace this line:

RewriteRule ^(.*)$ index.php [QSA,L]

By this line:

RewriteRule ^.*$ index.php [QSA,L]

And it should work.