url encoded values

Topics: Developer Forum, User Forum
Apr 24, 2007 at 12:59 PM
I have a rule in my .ini file that looks something like this:

RewriteRule ^/website/FunGames$ /website/Page.aspx?id=fun+%26+games I

Where the %26 is a url encoded ampersand (&). If I type /website/fungames into the address bar, it takes me to page.aspx but it doesn't do anything with the query string. If I type /website/Page.aspx?id=fun+%26+games into the address bar, it works just fine, showing the content for fun & games. I have set breakpoints and checked the rawurl for the page and it is /website/page.aspx?id=fun+games, so it seems that the rewriter is just taking out the +%26. I've spent a little time looking through the code to see if there is some way I can fix it but I haven't found anything.

Anyone have any ideas?
Coordinator
Apr 25, 2007 at 5:15 PM
Have you tried replacing the %26 in the replacement pattern with just an ampersand?
(Why do you need to escape it anyway?)

According to the README file for IIRF, the %26 should be interpreted as a reference to the most recently matched strings in a RewriteCond statement. So %26 means, the 26th most-recently matched string. It does not translate into ampersand, in the context of the replacement string.

excerpt:
The replacement string can contain:
 
- constant text
 
- references to the matched substrings in the input, in the form
  of $n, where n is a digit. (Eg $1, $2, $3...).  These are
  called back-references. 
 
- references to the matched substrings in the most recently
  evaluated RewriteCond associated to that RewriteRule.  These
  take the form %n, where n is a digit. (Eg %1, %2, %3...)
 
- references to server variables.  Eg, %{QUERY_STRING} in the
  replacement pattern embeds the query string of the incoming
  request, into the output (rewritten) URL. 
Apr 25, 2007 at 7:17 PM
I need to url encode the ampersand because it is part of the query string. I want the value "fun & games" passed in the query string so that I can use it on the next page to query the database. If I replace the %26 with a & then the Request.QueryString"id" would return just "fun" since the ampersand is a delimeter.

Is there no way to escape the %26 so that the url rewriter knows that I mean, literally, "%26" and not "the 26th most-recently matched string"?
Coordinator
Apr 26, 2007 at 11:42 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Apr 27, 2007 at 12:04 AM
Ahh, I see. We'd need to change the parsing of the replacement string to allow escaping of special characters like this. So that, for example, %% in the replacement string gets reduced to % in the output. So you would need %%26 to get what you want.

I've made the change, you will need to test it to make sure it works. Try release v1.2.12a.