2014-05-08 31 views
0

我有這樣的規則,在我的.htaccess的.htaccess重寫規則不讀的最後兩個參數

RewriteRule ^clothes/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ products.php?g=$1&$2=$3&$4=$5&$6=$7&$8=$9&$10=$11 [L] 
RewriteRule ^clothes/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ products.php?g=$1&$2=$3&$4=$5&$6=$7&$8=$9 [L] 
RewriteRule ^clothes/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ products.php?g=$1&$2=$3&$4=$5&$6=$7 [L] 
RewriteRule ^clothes/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ products.php?g=$1&$2=$3&$4=$5 [L] 
RewriteRule ^clothes/([^/]+)/([^/]+)/([^/]+)/?$ products.php?g=$1&$2=$3 [L] 
RewriteRule ^clothes/([^/]+)/?$ products.php?g=$1 [L] 

它可以像website.com/clothes/women/type/tshirts/brand/nike/color/red/size/s/price/0-29 ,這應該是print_r($_GET)

Array 
(
    [g] => women 
    [type] => tshirts 
    [color] => red 
    [brand] => nike 
    [size] => s 
    [prezzo] => 0-29 
) 

於是開始from website.com/clothes/women/然後我可以添加過濾器/值對,然後到達可以使用所有可能的過濾器的地址。

的問題是,最後一個過濾器/值對不工作,從第一條規則這個片段在.htaccess [..]&$10=$11。因此,而不是aspected轉儲的數據,我得到這個

Array 
(
    [g] => women 
    [type] => tshirts 
    [color] => red 
    [brand] => nike 
    [size] => s 
    [women0] => women1 
) 

所以基本上它取代了最後一個過濾器/值對第一濾波器,g=$1的名稱。

有多少個參數可以傳入url的參數.htaccess是否有限制?在我看來,最後一個參數是$9,所以$10沒有考慮在內。

如果是這樣,我可以解決這個問題嗎?

謝謝。

+1

您只能使用'$ 0到$ 9'捕獲的組。 – anubhava

+0

謝謝,這就是我的想法。 –

回答

0

可以通過讓這個遞歸規則克服這個mod_rewrite。將其放置在根目錄下.htaccess:

RewriteEngine On 
RewriteBase/

RewriteRule ^(clothes/[^/]+)/([^/]+)/([^/]*)(/.*)?$ $1/$4?$2=$3 [L,QSA,NC] 
RewriteRule ^clothes/([^/]+)/?$ products.php?g=$1 [L,QSA,NC] 
+0

我真的不知道如何做到這一點的行爲,現在我不能測試,但就其結果是一樣的嗎?謹慎解釋?謝謝。 –

+0

這是解決你碰到即超過9個拍攝組的問題。它通過重複執行相同的重寫規則來解決它。測試一下,讓我知道。如果有效,我可以添加更詳細的解釋。 – anubhava