url-rewritingtuckey-urlrewrite-filter

URL Forwarding based on request parameters


I am using UrlRewriteFilter from http://www.tuckey.org/urlrewrite/. Mainly I am trying to get the following URL
http://domain/application/?param=value to redirect to
http://domain/application/?another_param=another_value (simply replacing the request param).
Below are my rule configuration that dosen't seem to work

    <rule>
    <from>^(.*?param=value)$</from>
    <to type="forward">%{context-path}?another_param=another value</to>
</rule>

I have tried several other variations but that didn't seem to work either. any light shed on this issue would be much appreciated


Solution

  • I have been able to resolve the issue using the rule below

     <rule>
        <name>Selective redirect example redirect</name>
        <condition type="parameter" name="param" operator="equal">value</condition>
        <to type="forward">?another_param=another_value</to>
    </rule>
    

    The key to the answer here is using the conditions rather than depending on the rule to capture the request, in my case I needed only to apply the rule when a certain param value is met. The second part of the answer is removing the <from> tag, and hence all the requests that fulfill the condition will be redirected to the same source page.

    Finally, below are the links that were most useful in my search for the answer: