title: What causes Tuckey's UrlRewriteFilter to malform urlencoded unicode characters (e.g. %C3%B6 for ö) and how can I avoid it?
body: <p>We are using a simple UrlRewriteFilter rule to permanently (301) redirect HTTP requests <strong>without</strong> trailing slash to the same URL <strong>with</strong> trailing slash.</p>
  
  <p>In some cases our presentation layer needs URLs with encoded special characters  (e.g. %C3%B6 for ö) in it, which works fine as long as the UrlRewriteFilter is not involved. But when the rule kicks in I can see the encoded character getting malformed while redirecting, e.g.</p>
  
  <p><code>www.mydomain.com/asdf%C3%B6asdf/</code> --> 301 --> <code>www.mydomain.com/asdf%F6asdf/</code></p>
  
  <p><code>%F6</code> not being a valid unicode sequence (ending up as question mark in black diamond when urldecoded).</p>
  
  <p>We use UTF-8 throughout our application, it's set in response headers as well as in the HTML's <code>&lt;head&gt;</code> section. The malformed encoding occurs on Windows and Linux machines. The rewrite rule looks as follows</p>
  
  <pre><code>&lt;rule enabled="true" match-type="regex" &gt;
      &lt;name&gt;Force trailing slash&lt;/name&gt;
      &lt;note&gt;...&lt;/note&gt;
      &lt;condition type="request-uri" operator="notequal"&gt;...&gt;/condition&gt; &lt;!-- some URLs shall not be redirected --&gt;
      &lt;from&gt;(^[^\?]*)(\?.*)?$&lt;/from&gt;
      &lt;to type="permanent-redirect" last="true" &gt;$1/$2&lt;/to&gt; &lt;!-- adding trailing slash and query string, if present --&gt;
  &lt;/rule&gt;
  </code></pre>
  
  <p>I'd be happy for any ideas how this could be solved. I've played with the <code>decode-using</code> and <code>encode</code> attributes, but it did not help.</p>