tomcathttp-redirecturl-rewritingurlrewriter

using UrlRewriteFilter not redirecting properly


This is my

<urlrewrite>
    <rule>
      <name>Canonical Hostnames</name>
      <condition name="host" operator="equal">^example\.com</condition>
      <condition name="host" operator="notequal">^$</condition>
      <from>^/(.*)</from>
      <to type="redirect" last="true">http://www.example.com/$1</to>
    </rule>
</urlrewrite>

It is redirectiing well to www.example.com but the problem is http://example.com/resetpassword/?user=2560256&token=1233 is redirected to http://example.com/resetpassword


Solution

  • To preserve the query string, you can add the use-query-string parameter to the urlrewrite element as follows:

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

    Alternatively, you can include the query string in your redirect URL as follows:

    <to type="redirect" last="true">http://www.example.com/$1?%{query-string}</to>
    

    See the documentation here.