gpt4 book ai didi

java - Tuckey urlRewriteFilter 使用查询字符串 ="true"不起作用?

转载 作者:搜寻专家 更新时间:2023-11-01 01:55:53 29 4
gpt4 key购买 nike

我正在尝试使用 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

改写为

https://server.com/test.jsp

我做错了什么吗?感谢您的任何建议。

最佳答案

version 4.0 ,可以对 to 属性使用 qsappend 属性。 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 以下的版本,您可以在 URL 的末尾使用 ?%{query-string}

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

关于java - Tuckey urlRewriteFilter 使用查询字符串 ="true"不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9491167/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com