2010-02-02 155 views
1

這是工作:.htacces重寫規則問題

RewriteRule ^([a-z]{2}/){0,1}showCategory/([0-9]*)/([0-9]*)(/{0,1})$    /main.php?id=$2&il[lang]=$1&page=$3 [L] 

這個網址:

http://localhost/showCategory/590/10 

現在,我想這也工作:

http://localhost/showCategory/590/transport/10 

我嘗試的規則:

RewriteRule ^([a-z]{2}/){0,1}showCategory/([0-9]*)/([a-z\-_0-9\+]*)/([0-9]*)(/{0,1})$    /main.php?id=$2&il[lang]=$1&page=$3 [L] 

如何更改RewriteRule

回答

1

這一個工程有兩個URL

RewriteRule ^([a-z]{2}/)?showCategory/([0-9]+)(?:/[A-Za-z0-9_-]+)?/?([0-9]+)/?$ /main.php?id=$2&il[lang]=$1&page=$3 [L] 

我也是{0,1}與簡化?這也是一樣的。

的關鍵是(?:/[A-Za-z0-9_-]+)?,解釋:

(?:     Non-capturing group, so what's in here will not be put in any $n 
/     Match the slash 
    [A-Za-z0-9_-]+  Match any word with letters/numbers/dashes/underscores 
)?     Close non-capturing group, and the ? means it's optional 
+0

謝謝,沒關係!它是如何工作的? – 2010-02-02 18:36:39

+0

我用解釋更新了答案 – adamJLev 2010-02-02 18:43:01

+0

RewriteRule ^([az] {2} /){0,1} showCategory /([0-9] *)/ [az \ -_ 0-9 \ +] */mp/(。*)(/ {0,1})$ /main.php?id=$2&il[lang]=$1&$3 [L] RewriteRule ^([az] {2} /){0,1} showCategory /([0-9]*)/[az\-_0-9\+]*/(.*)/mp/(.*)(/{0,1})$ /main.php?id=$2 &[lang] = $ 1&page = $ 3&$ 4 [L] RewriteRule ^([az] {2} /){0,1} showCategory /([0-9] *)(/ {0,1})/ [az] -_ 0-9 \ +] * $ /main.php?id=$2&il[lang]=$1 [L] RewriteRule ^([az] {2} /){0,1} showCategory /([ 0-9] *)/ [az \ -_ 0-9 \ +] * /([0-9] *)(/ {0,1})$ \t \t \t \t \t /main.php?id=$2&il [lang] = $ 1&page = $ 3 [L] – 2010-02-02 19:19:17

1

試試這個規則:

RewriteRule ^([a-z]{2}/)?showCategory/([0-9]+)/[a-z-_0-9+]+/([0-9]+)/?$ /main.php?id=$2&il[lang]=$1&page=$3 [L] 
+0

謝謝,沒關係! 它是如何工作的? – 2010-02-02 18:25:16

+0

@Viktor Onozo:如何工作? – Gumbo 2010-02-02 19:57:06