Forum Discussion

D_T's avatar
D_T
Icon for Cirrus rankCirrus
Jan 21, 2022

iRule Query String Match and Redirect

I seem to be having difficulty finding too much on this and maybe it is as simple as it is, I am looking to perform a URI match with a few particular query strings and redirect to another website if the request is found. I have found a few articles indicating using a datagroup but this seems a bit excessive for the task I am looking at.

Example:

https://www.thedomain.com/dir1/index.html?newpath=Name1 -> https://www.newdomain.com/dir1/index.html?newpath=Name1

Is this as simple as something like:

when HTTP_REQUEST {
   if { ( [string tolower [HTTP::host]] equals "www.thedomain.com" 
) and ( [string tolower [HTTP::uri]] ends_with "Name1" ) } {
       HTTP::redirect "http://www.newdomain.com[HTTP::uri]"
   }
}

Will the query string after the "?" be picked up and carried over with [HTTP::uri]?