dpd3982 2013-09-18 08:51
浏览 27

Flight PHP REST服务总是返回“Hello World”

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:

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?

  • 写回答

2条回答 默认 最新

  • dongyi6195 2015-01-28 17:15
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用