URL Rewrite Filter not working with query parameters containing special characters

风流意气都作罢 提交于 2019-12-23 17:06:27

问题


I'm using URL Rewrite Filter to forward some ugly URLs to pretty Urls. Referring to Conditions Based On URL Parameters, I’ve done something using UrlRewriteFilter which is actually required to make my site Google crawl-able. Here’s how it goes.

<rule enabled="true">
        <note>
            The rule means that requests to /test/status/ will be redirected to /rewrite-status
            the url will be rewritten.
        </note>
        <condition type="parameter" name="_escaped_fragment_" operator="equal">(apple|kiwi|orange)</condition>
            <from>^/mysite/(.+)/(.*)$</from>
            <to type="redirect">/mysite/%{parameter:_escaped_fragment_}</to>
    </rule>

It fails throwing java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern – %%7. As my variable contains underscores (_escaped_fragment_), where in it works fine with a parameter variable called ‘friuit’. Please help me get out of it.


回答1:


<rule>
<condition name="_escaped_fragment_" type="parameter" operator="equal">(apple|kiwi|orange)</condition>
<to type="redirect">/mysite/%1</to>
</rule>

Using the value of a query parameter with %{parameter:_escaped_fragment_} would work only with words containing no special characters. where in %1 (that is % followed by query parameter index) will work for any, which solved my problem.



来源:https://stackoverflow.com/questions/23803564/url-rewrite-filter-not-working-with-query-parameters-containing-special-characte

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!