replace all ampersands or qmarks in query string

Topics: User Forum
Feb 12, 2011 at 12:32 AM

I'm working on a solution where I'm trying to rewrite a URL that was originally came from a Google search appliance. It's for an internal proxy were I'm using a ColdFusion app to serve as a proxy between clients and our Google search appliance.

The URLs I'm trying to process in IIRF look like this "", with a few more values in that query string, typically.

What I'm trying to accomplish is to take all the variables in the query string, and rewrite them to "index.cfm?vars=" and the variables, with all the ampersands escaped.

The problem is, there will an unknown number of variables, and thus, an unknown number of ampersands in the query string.

My problem is, and I've used IIRF for some time now, I just do not see a way to do a "replace all" on all occurences of ampersands in a query string, to change them to something else like the html-escaped equivalent. Is there a way to do this?

Feb 18, 2011 at 5:19 PM

yes, there's a way to do it; you can check the examples in the IIRF source release for some hints.  I just looked in the IIRF documentation but didn't see any examples that were particularly for this case.

What I would suggest you do is rewrite the incoming URL, replacing ampersand with a URL-encoded value for ampersand, repeatedly, until there are no more ampersands present in the URL .

Then one last rewrite to capture the query string, everything that follows the ? in the original URL, and put that as the value for the var parameter.

## This rule fires repeatedly until there are no more ampersands
RewriteRule ^/(.+)\?(.+)&(.+)$  /$1?$2%%26$3
RewriteRule ^/(.+)\?(.+)$         /index.cfm?vars=$2

I'm betting that there will be more twists to your case, but you can start with that and figure out what else you need to do.

ps: you may need to turn off url decoding on incoming URLs by including a "UrlDecoding OFF" directive into the ini file - try it and see.




Feb 20, 2011 at 2:48 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Nov 2, 2011 at 9:22 AM

Hi Cheeso,


I have a follow-up to this discussion in the work item for version

Nov 2, 2011 at 4:39 PM

open a new thread and reference the relevant workitem there.