
Question:
I'm using URL Rewrite Filter to forward some ugly URLs to pretty Urls. Referring to <a href="http://devtidbits.com/2011/11/28/tuckey-urlrewrite-how-to/" rel="nofollow">Conditions Based On URL Parameters</a>, 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.
Answer1:
<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.