我正在使用来自 tukey ( http://www.tukey.org/urlrewrite/ )的 URLRewrite 过滤器
现在我创建了一些规则,但是有一个案例让我很头疼。URL:/group/1/update应该改写为:/group?id=1&action=update
我为这种情况创建了一个正则表达式模式:^/group/([0-9]+)/(\w*)$,但过滤器无法重写它。没有比赛。
在我的 TestCase 中,我通过我所有的模式运行了这个 url,只是为了检查。我如预期的那样找到了比赛。
assertFalse( "/group/1/update".matches("^/group/create$") );
assertFalse( "/group/1/update".matches("^/group/save$") );
assertFalse( "/group/1/update".matches("^/group/([0-9]+)/?$") );
assertTrue( "/group/1/update".matches("^/group/([0-9]+)/(\\w*)$") );
assertFalse( "/group/1/update".matches("^/group/([0-9]+)/(\\w*)\\?(.*)+$") );
那么为什么过滤器找不到规则呢?
只是为了包括所有内容,这是我的 urlrewrite.xml,或者它的一部分:
<rule>
<from>^/group/create$</from>
<to>/group?action=create</to>
</rule>
<rule>
<from>^/group/save$</from>
<to>/group?action=save</to>
</rule>
<rule>
<from>^/group/([0-9]+)/?$</from>
<to>/group?id=$1&action=show</to>
</rule>
<rule>
<from>^/group/([0-9]+)/(\\w*)$</from>
<to>/group?id=$1&action=$2</to>
</rule>
<rule>
<from>^/group/([0-9]+)/(\\w*)\\?(.*)+$</from>
<to>/group?id=$1&action=$2&$3</to>
</rule>
再见
阿德里安