【发布时间】:2016-03-15 06:17:06
【问题描述】:
我的.htaccess 看起来像
RewriteEngine On
RewriteRule ^api/([^/]*)$ /api.php?method=$1 [L,QSA]
我的api.php 看起来像
class API {
public function __construct()
{
require_once('helpers.php');
}
public function test()
{
dd('hey');
}
};
$api = new API;
$method = isset( $_GET['method'] ) ? $_GET['method'] : null;
dd($_REQUEST, $_GET);
if( $method && method_exists($api, $method) ){
$api->{$method}();
}
else {
exit("Nothing to see here governor.");
}
然而,当我访问重写的网址时,例如site.com/api/test我明白了
array (size=0)
empty
如果我将其更改为 /api.php?method=test 或 /api/test?method=test 我得到
array (size=1)
'method' => string 'test' (length=4)
为什么无法检测到查询字符串?
服务器设置为 apache 2.2, php-fmt 5.6
谢谢
【问题讨论】:
标签: php .htaccess mod-rewrite query-string