开发者

Regular expression for replace?

开发者 https://www.devze.com 2023-03-15 04:58 出处:网络
I am trying to replace relative url from /abc/bbc.do?count=1 with /bbc.do?count=1 using urlrewritefilter but when I am using the regular expression /abc/(.*)$ and redirect to /1$ it only seems to be c

I am trying to replace relative url from /abc/bbc.do?count=1 with /bbc.do?count=1 using urlrewritefilter but when I am using the regular expression /abc/(.*)$ and redirect to /1$ it only seems to be capturing bbc.do and not url parameters. Any suggestions?

开发者_StackOverflow中文版
<rule match-type="regex">
    <from>^/abc/(.+)$</from>
    <to type="redirect">/$1</to>
</rule>


Update

It looks like the begin anchor is fine, but the backreferences use % instead of $. Solution is updated.

<rule match-type="regex">
    <from>^/abc/(.+)$</from>
    <to type="redirect">/%1</to>
</rule>

Also, make sure to add use-query-string="true" to your urlrewrite node. It is false by default.

<urlrewrite use-query-string="true">
0

精彩评论

暂无评论...
验证码 换一张
取 消