简体   繁体   English

URL Rewrite Filter不使用包含特殊字符的查询参数

[英]URL Rewrite Filter not working with query parameters containing special characters

I'm using URL Rewrite Filter to forward some ugly URLs to pretty Urls. 我正在使用URL重写过滤器将一些丑陋的URL转发给漂亮的Url。 Referring to Conditions Based On URL Parameters , I've done something using UrlRewriteFilter which is actually required to make my site Google crawl-able. 参考基于URL参数的条件 ,我已经使用UrlRewriteFilter做了一些事情,这实际上是让我的网站谷歌可以爬行所必需的。 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. 它无法抛出java.lang.IllegalArgumentException:URLDecoder:转义(%)模式中的非法十六进制字符 - %% 7。 As my variable contains underscores (_escaped_fragment_), where in it works fine with a parameter variable called 'friuit'. 由于我的变量包含下划线(_escaped_fragment_),因此在其中使用名为'friuit'的参数变量可以正常工作。 Please help me get out of it. 请帮我摆脱它。

<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. 使用带有%{parameter:_escaped_fragment_}的查询参数的值仅适用于不包含特殊字符的单词。 where in %1 (that is % followed by query parameter index) will work for any, which solved my problem. %1 (即%后跟查询参数索引)将适用于任何,这解决了我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM