$_request ["request"] in a restful api


$_request ["request"] in a restful api

我正在学习编写一个restful api,我对本教程中的一些代码感到困惑。

http://coreymaynard.com/blog/creating-a-restful-api-with-php/

他们使用

$_REQUEST["request"]

用于请求uri。我正在努力理解为什么我会这样做而不是

$_SERVER["request_uri"]

$_REQUEST调用从GET或POST获取名为"REQUEST"的变量的值(本教程中仅接受GET)$_SERVER["request_uri"]获取用于访问页面的uri

http://php.net/manual/en/reserved.variables.server.php

我想明白了。我花了太少的时间阅读.htaccess代码,这一切都毫无意义。

下面是简介:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule api/v1/(.*)$ api/v1/api.php?request=$1 [QSA,NC,L]
</IfModule>

RewriteRule声明在api/vi/(.*)路径上请求的任何内容都将重定向到路径api/v1/api.php?请求=$1。它在末尾添加的变量是我们使用$_request["request"]检索的请求变量。