这是我想做的事情:
/gestion/aa/ => /gestion/aa.php
/gestion/bb/ => /gestion/bb.php
/gestion/a/b/ => /gestion/a/b.php
/gestion/a/b/c/ => /gestion/a/b/c.php
/cmd/aa/ => /cmd/aa.php
/cmd/bb/ => /cmd/bb.php
/cmd/a/b/ => /cmd/a/b.php
/cmd/a/b/c/ => /cmd/a/b/c.php
/json/aa/ => /json/aa.php
/json/bb/ => /json/bb.php
/json/a/b/ => /json/a/b.php
/json/a/b/c/ => /json/a/b/c.php
这让我想到了这个简单的正则表达式:
^/(gestion|cmd|json)/(([^/]+/)*)$ /$1/$2.php [QSA,L]
问题在于$2
总是 /
,结果是:
/json/aa/ => /json/aa/.php
/json/bb/ => /json/bb/.php
/json/a/b/ => /json/a/b/.php
/json/a/b/c/ => /json/a/b/c/.php
知道如何获得正确的正则表达式吗?
答案 0 :(得分:1)
^/(gestion|cmd|json)/(.+)/$ /$1/$2.php [QSA,L]
应该做的伎俩
答案 1 :(得分:0)
使用此:
^(gestion|cmd|json)(/.*)/$ /$1$2.php