Tomcat – URL rewriting with TomCat

rewritetomcat

I am looking to rewrite an incoming url request on TomCat with the Tuckey rewriter:

<rule>
<from>/OutputFile?sourceArticleId=([0-9]+)</from>
<to>/app/clipping/get/$1</to>
</rule>

the "?" question mark fails the regexp pattern matching. How can I properly escape it or what is the correct solution for this?

Best Answer

I' m not too familiar with reg exp in urlrewrite but you can try:

<from>/OutputFile\?sourceArticleId=([0-9]+)</from>

In many languages, the escaping character is the \

Update:

According to the doc, by default, the query string is not included in the <from> element. So you can try with the use-query-string set in the urlrewrite

Also make sure that the default-match-type in the <urlrewrite> is set to regex (I use the Spring MVC template from STS and it is set to wildcard by default

<urlrewrite use-query-string="true">
<rule match-type="regex">
    <from>/OutputFile\?sourceArticleId=([0-9]+)</from>
    <to>/app/clipping/get/$1</to>
</rule>
...