需要htaccess规则来区分目录和查询字符串


Need htaccess rule to differentiate directories and query strings

我有一个url,如下所述。

abc.com/test/abc/hello/?hello=world&foo=bar

我必须使用htaccess 来区分目录和查询字符串

我需要有这样的结果:

Array
(
    [data] => test/abc/hello/
    [hello] => world
    [foo] => bar
)

我尝试了很多htaccess方法,但都没有得到我想要的结果。我已经尝试了以下方法

如果我尝试过:

RewriteRule ^(['w'-'/]+)$ index.php?data=$1

输出:

Array
(
    [data] => test/abc/hello/
)

尝试时:

RewriteRule .* test.php [L]

输出:

Array
(
    [hello] => world
    [foo] => bar
)

但建议我访问规则,我可以从中得到像一样的结果

Array
(
    [data] => test/abc/hello/
    [hello] => world
    [foo] => bar
)

有人能帮我从htaccess 获得结果吗

这可能有效(未测试):

RewriteEngine On
RewriteRule ^(['w'-'/]+)$ index.php?data=$1 [L,QSA]

标志QSA:追加QueryString。

但我很保守,因为你用它来获取数据,你好,这太昂贵了。在PHP中,您可以使用以下内容:

<?php
$data = $_SERVER["REQUEST_URI"];
$hello = $_GET["hello"];
$foo = $_GET["foo"];
?>

不需要任何重写。