Tuckey urlRewriteFilter use-query-string = "true" doesn't work?

I am trying to use Tuckey urlRewriteFilter to rewrite any URLs in https: //, while preserving any query string parameters that have been added 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 use-query-string = "true" would do 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 does not seem to be happening. It happens that

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

corresponded as

https://server.com/test.jsp

Am I doing something wrong? Thanks for any advice.

+4
source share
2 answers

Since version 4.0 , you can use the qsappend attribute for the to property. The default qsappend value is false, so you need to enable it.

So the solution might 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> 
+6
source

Try the following:

 <rule> <from>^(.*)$</from> <to last="true" type="permanent-redirect">https://%{server-name}$1</to> </rule> 

Be sure to add ' use-query-string="true" ' to the urlrewrite tag

0
source

Source: https://habr.com/ru/post/1398915/


All Articles