Technical Forum
Ask questions. Discover Answers.
cancel
Showing results for 
Search instead for 
Did you mean: 

iRule Query String Match and Redirect

D_T
Cirrus
Cirrus

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]?

3 REPLIES 3

D_T
Cirrus
Cirrus

Or even simpler

When HTTP_REQUEST {
    if{ [HTTP::uri] contains “*?newpath=Name1" } {HTTP::redirect "https://www.newdomain.com/dir1/index.html?newpath=Name1 } }

D_T
Cirrus
Cirrus

Anyone on this?

You need to just play with F5 as many questions can be answered just by playing around. For this maybe  see:

https://clouddocs.f5.com/api/irules/HTTP__query.html

https://clouddocs.f5.com/api/irules/URI__query.html

 

With HTTP:Respond you may use a different temporary redirect code etc.:

 

https://clouddocs.f5.com/api/irules/HTTP__redirect.html