URL重写筛选器不适用于包含特殊字符的查询参数 [英] URL Rewrite Filter not working with query parameters containing special characters

查看:166
本文介绍了URL重写筛选器不适用于包含特殊字符的查询参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用URL重写过滤器将一些难看的URL转发到漂亮的Urls. 参考基于URL参数的条件, 我已经使用UrlRewriteFilter进行了某些操作,实际上这是使我的网站可抓取Google所需的. 就是这样.

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>

它无法引发java.lang.IllegalArgumentException:URLDecoder:转义(%)模式中的非法十六进制字符– %% 7. 由于我的变量包含下划线(_escaped_fragment_),因此在其中可以与名为"friuit"的参数变量配合使用. 请帮助我摆脱困境.

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.

推荐答案

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

将查询参数的值与%{parameter:_escaped_fragment_}一起使用仅适用于不包含特殊字符的单词. %1中的哪个位置(即%后面紧跟查询参数索引)将适用于任何位置,这解决了我的问题.

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.

这篇关于URL重写筛选器不适用于包含特殊字符的查询参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆