PHP API 在 REST 实现中不起作用


PHP API not working in REST implementation

我正在尝试使用PHP构建一个简单的RESTful API。该请求适用于 URL 路径中的普通查询,但是,我在实施 REST 方法时收到"找不到 404 URL"错误

.htaccess

Options +FollowSymlinks
RewriteEngine On
RewriteRule ^([a-zA-Z|_-]*)$ index.php?name=$1 [nc,qsa]

索引.php(代码段)

// process client request (via URL)
header("Content-Type:application/json");
include('functions.php');
if(!empty($_GET['name'])){
    $name=$_GET['name'];
    $result=get_items_by_category("$name");
    if(empty($result)){
      print($name);
      deliver_response(200,"Duh, gee, Mort, there's nothing here!",NULL);
      }else{
      deliver_response(200,"Hit the road,Jack!",$result);
      }
  }else{
  deliver_response(400,"This is not the request you're looking for",NULL);
}

引用:

I did some more debugging, and I found out that /api/Grill(my) does not work, 
maybe due to parentheses in the name? Because /api/Pasta works

正则表达式中没有括号,所以是的,它不会匹配。

您对 URL 语法的计划是什么? 可以帮助您使用正则表达式使其工作。