PHP 看不到来自 RewriteRule 的查询字符串

PHP cant see query string from RewriteRule

我的.htaccess长得像

RewriteEngine On
RewriteRule ^api/([^/]*)$ /api.php?method= [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.");
}

然而,当我访问重写的 url 例如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

谢谢

因为 URI 开始 api 是相同的 PHP 处理程序 api.php 我怀疑这是 MultiViews.

的问题

在 .htaccess 的开头使用此行将其关闭:

Options -MultiViews

MultiViews 选项由 Apache 的 content negotiation 模块使用,该模块运行 before mod_rewrite 并使 Apache 服务器匹配文件的扩展名。所以 /api 可以在 URL 中,但它将服务于 /api.php.