我正在尝试使用Tuckey urlRewriteFilter将任何URL重写为https://,同时保留附加到URL的任何查询字符串参数。我的urlrewrite.xml文件目前看起来像
<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>
我认为use-query-string =“true”可以实现这一点,所以
http://server.com/test.jsp?company=3&id=1
将被重写为
https://server.com/test.jsp?company=3&id=1
但这似乎并没有发生。会发生什么
http://server.com/test.jsp?company=3&id=1
被重写为
我做错了吗?谢谢你的任何建议。
答案 0 :(得分:7)
从version 4.0开始,可以对qsappend
属性使用to
属性。 qsappend
的值默认为false,因此您必须启用它。
所以解决方案可以是,
<rule match-type="regex">
<from>^.*$</from>
<to type="permanent-redirect" qsappend="true" last="true">https://%{server-name}%{request-uri}</to>
</rule>
更新:对于4.0以下的版本,您可以在网址末尾使用?%{query-string}
<rule match-type="regex">
<from>^.*$</from>
<to type="permanent-redirect" last="true">https://%{server-name}%{request-uri}?%{query-string}</to>
</rule>
答案 1 :(得分:0)
试试这个:
<rule>
<from>^(.*)$</from>
<to last="true" type="permanent-redirect">https://%{server-name}$1</to>
</rule>
请务必添加&#39; use-query-string="true"
&#39;在urlrewrite标签上