.htacces重写规则问题
问题描述:
这是工作:.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
?
答
这一个工程有两个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
答
试试这个规则:
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
谢谢,没关系!它是如何工作的? – 2010-02-02 18:36:39
我用解释更新了答案 – adamJLev 2010-02-02 18:43:01
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