2017-02-04 50 views
1

要:http://localhost:3000/rr/uu 有:失敗htaccess的重定向CLEN

RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)$ index.php?param=$1&param2=$2 

作品。

添加只是一個參數:

RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)$ index.php?param=$1&param2=$2&param3=$3 

,並打算:

http://localhost:3000/rr/uu/gg

結果中找不到Apache的錯誤消息。爲什麼?

+0

你的規則只接受2 perameters – starkeen

+0

可以使您的評論的答案,我會選擇它。謝謝。 –

回答

1

你的規則需要3個捕獲組,嘗試:

RewriteRule ^([^/]+)/?(.*)/?(.*)/?$ /index.php?perm=$1&perm2=$1&perm3=$3 [L] 
+0

這個(和我的例子)似乎強制3個參數或它不會工作。有沒有辦法使它有條件,因此它可以用於1到3個參數? –

+1

@RobertBrax我已根據您的要求更新了代碼。現在規則中最後2個捕獲組是可選的。 – starkeen

+0

非常感謝。 –