Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tuckey urlRewriteFilter use-query-string="true" not working?

I'm trying to use Tuckey urlRewriteFilter to rewrite any URLs to https://, while preserving any query string parameters that were appended to the URL. My urlrewrite.xml file currently looks like

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

<rule>
    <note>
        The rule means that requests to /test/status/ will be redirected to /rewrite-status
        the url will be rewritten.
    </note>
    <from>/test/status/</from>
    <to type="redirect">%{context-path}/rewrite-status</to>
</rule>

<rule match-type="regex">
   <condition type="header" operator="notequal" name="X-Forwarded-Proto">^HTTPS$</condition>
   <condition type="request-uri" operator="notequal">/station/StationPingServlet</condition>
   <condition type="request-uri" operator="notequal">/station/StudioPingServlet</condition>
   <from>^.*$</from>
   <to type="permanent-redirect" last="true">https://%{server-name}%{request-uri}</to>
</rule>

<outbound-rule>
    <note>
        The outbound-rule specifies that when response.encodeURL is called (if you are using JSTL c:url)
        the url /rewrite-status will be rewritten to /test/status/.

        The above rule and this outbound-rule means that end users should never see the
        url /rewrite-status only /test/status/ both in thier location bar and in hyperlinks
        in your pages.
    </note>
    <from>/rewrite-status</from>
    <to>/test/status/</to>
</outbound-rule>

I thought that use-query-string="true" would accomplish this, so

http://server.com/test.jsp?company=3&id=1

will be rewritten to

https://server.com/test.jsp?company=3&id=1

but this doesn't seem to be happening. What happens is that

http://server.com/test.jsp?company=3&id=1

is rewritten as

https://server.com/test.jsp

Am I doing anything wrong? Thanks for any advice.

like image 356
user619804 Avatar asked Feb 28 '12 23:02

user619804


1 Answers

Since version 4.0 , it is possible to use qsappend attribute for to property. The value of qsappend is by default false, so you have to enable it.

So the solution can be,

<rule match-type="regex">
   <from>^.*$</from>
   <to type="permanent-redirect" qsappend="true" last="true">https://%{server-name}%{request-uri}</to>
</rule>

UPDATE: For versions below 4.0, you can use ?%{query-string} at the end of your URL

<rule match-type="regex">
   <from>^.*$</from>
   <to type="permanent-redirect" last="true">https://%{server-name}%{request-uri}?%{query-string}</to>
</rule>
like image 121
vtor Avatar answered Sep 28 '22 23:09

vtor