Tuckey urlRewriteFilter use-query-string = "true" не работает? - PullRequest
4 голосов
/ 29 февраля 2012

Я пытаюсь использовать 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

Я что-то не так делаю?Спасибо за любой совет.

Ответы [ 2 ]

7 голосов
/ 25 июля 2012

Поскольку версия 4.0 , можно использовать атрибут qsappend для свойства to.Значение qsappend по умолчанию ложно, поэтому вы должны включить его.

Таким образом, решение может быть,

<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} в конце вашего URL

<rule match-type="regex">
   <from>^.*$</from>
   <to type="permanent-redirect" last="true">https://%{server-name}%{request-uri}?%{query-string}</to>
</rule>
0 голосов
/ 18 января 2016

Попробуйте это:

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

Обязательно добавьте 'use-query-string="true"' к тегу urlrewrite

...