23804

URL Rewrite Filter not working with query parameters containing special characters

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.

Recommend

  • Python BZ2 IOError: invalid data stream
  • htaccess mod_rewrite URL within subfolder
  • Trying to Graph a Simple Square in pyOpenGL
  • How to return a deferred promise and create a model with Ember.Deferred?
  • How to get google-services.json from Developer console?
  • Generating random numbers directly inside a .htaccess file
  • How to check disabled jobs with Jenkins server?
  • How to protect an asp:textbox from user input?
  • Zeromq with python hangs if connecting to invalid socket
  • F#: In which memory area is the continuation stored: stack or heap?
  • File extension of zlib zipped html page?
  • std::remove_copy_if_ valgrind bytes in block are possibly lost in loss record
  • Apache RewriteRule redirection with url encoded
  • presentShareDialogWithParams posts to FB wall, but callback handler results say error
  • How to write order and limit within cakephp joins array
  • Display issues when we change from one jquery mobile page to another in firefox
  • Deselecting radio buttons while keeping the View Model in synch
  • Can Jackson SerializationFeature be overridden per field or class?
  • Does CUDA 5 support STL or THRUST inside the device code?
  • Validaiting emails with Net.Mail MailAddress
  • MySQL WHERE-condition in procedure ignored
  • JSON with duplicate key names losing information when parsed
  • Which linear programming package should I use for high numbers of constraints and “warm starts” [clo
  • Javascript + PHP Encryption with pidCrypt
  • When should I choose bucket sort over other sorting algorithms?
  • How to make Safari send if-modified-since header?
  • How do you troubleshoot character encoding problems?
  • Web-crawler for facebook in python
  • Jquery - Jquery Wysiwyg return html as a string
  • CSS Applying specific rule for a specific monitor resolution with only CSS is posible?
  • Understanding cpu registers
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • sending mail using smtp is too slow
  • Busy indicator not showing up in wpf window [duplicate]
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • How can I use `wmic` in a Windows PE script?
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?