$_request ["request"] 在 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
我明白了。我花了太少时间阅读 .htaccess 代码,这一切都毫无意义。
所以这里是概要:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule api/v1/(.*)$ api/v1/api.php?request= [QSA,NC,L]
</IfModule>
此 RewriteRule 声明在 api/vi/(.*) 路径上请求的任何内容都将重定向到路径 api/v1/api.php?request=$1。它在最后添加的变量是我们使用$_REQUEST["request"]来检索的请求变量。
我正在学习编程 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
我明白了。我花了太少时间阅读 .htaccess 代码,这一切都毫无意义。
所以这里是概要:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule api/v1/(.*)$ api/v1/api.php?request= [QSA,NC,L]
</IfModule>
此 RewriteRule 声明在 api/vi/(.*) 路径上请求的任何内容都将重定向到路径 api/v1/api.php?request=$1。它在最后添加的变量是我们使用$_REQUEST["request"]来检索的请求变量。