2013-11-25 47 views
1

我有一個像下面提到的網址。需要htaccess規則來區分目錄和查詢字符串

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 

輸出:

​​

並試圖當:

RewriteRule .* test.php [L] 

輸出:

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

但建議我htaccess的規則,從中我能得到導致像

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

任何人可以幫助我從htaccess的

回答

1

這可能工作(未測試)得到我的結果:

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

標記QSA:添加了QueryString。

但我寧願保留,因爲你使用它來獲取數據,hello和foo,這太昂貴了。在PHP中,您可以使用:

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

不需要重寫。

+0

謝謝兄弟! 這條規則可以幫助我,並且正常工作 –

相關問題