use*_*804 5 java url-rewriting web tuckey-urlrewrite-filter
我正在尝试使用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>
Run Code Online (Sandbox Code Playgroud)
我认为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
被重写为
我做错了吗?谢谢你的建议.
从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>
Run Code Online (Sandbox Code Playgroud)
更新:对于4.0以下的版本,您可以?%{query-string}在URL的末尾使用
<rule match-type="regex">
<from>^.*$</from>
<to type="permanent-redirect" last="true">https://%{server-name}%{request-uri}?%{query-string}</to>
</rule>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5900 次 |
| 最近记录: |