【问题标题】:URL Rewrite Filter not working with query parameters containing special charactersURL 重写过滤器不适用于包含特殊字符的查询参数
【发布时间】:2014-05-22 09:59:20
【问题描述】:

我正在使用 URL 重写过滤器将一些丑陋的 URL 转发到漂亮的 URL。 参考Conditions Based On URL Parameters, 我已经使用 UrlRewriteFilter 做了一些事情,这实际上是使我的网站可被 Google 抓取所必需的。 事情是这样的。

<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”的参数变量一起正常工作。 请帮我摆脱它。

【问题讨论】:

    标签: url-rewriting filter seo tuckey-urlrewrite-filter


    【解决方案1】:
    <rule>
    <condition name="_escaped_fragment_" type="parameter" operator="equal">(apple|kiwi|orange)</condition>
    <to type="redirect">/mysite/%1</to>
    </rule>
    

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

    【讨论】:

    • 您想在您的代码中添加和解释吗?仅代码的答案很好,有解释的更好:)
    • user3686902 提供的解决方案非常有效!我很高兴给他 50 的声望。 @secretformula,他似乎是 StackOverflow 的新手。我可以更好地解释这一点。将查询参数的值与 %{parameter:_escaped_fragment_} 一起使用仅适用于不包含特殊字符的单词。 %1 中的哪里(即 % 后跟查询参数索引)适用于任何人,这解决了我的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-10
    • 1970-01-01
    • 2011-03-10
    • 1970-01-01
    • 1970-01-01
    • 2015-02-27
    相关资源
    最近更新 更多