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

Redirect to portion of a query string?

Nolan_Jensen
Cirrostratus
Cirrostratus

Hello All,

 

I am trying to figure out correct code for an iRule to redirect to a different host and append just a portion of the query string to the end of that redirect.

 

Example:

If customer goes to https://domain1.com/test.aspx?account=12345678 redirect them to https://domain2.com/12345678

 

I am able to use code below to add ?account=12345678 to the redirect but need it to just be the account number not the ?account= part of the query string.

my code results in this: https://domain2.com/?account=12345678

 

So ideally need to parse that query statement and pull just the account number to add to end of redirect.

 

Any help would be greatly appreciated. Thank you!

 

Here is the code I have that gets me close.

 

when HTTP_REQUEST {
  if { [string tolower [HTTP::uri]] contains "test.aspx" } {
        HTTP::redirect " https://domain2.com/[HTTP::query]"
    }
}

 

1 ACCEPTED SOLUTION

Hi Nolan Jensen,

when HTTP_REQUEST {
	if { [string tolower [HTTP::uri]] contains "test.aspx" } {
		HTTP::redirect "https://domain2.com/[URI::query [HTTP::uri] account]"
	}
}

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

View solution in original post

3 REPLIES 3

Hi Nolan Jensen,

when HTTP_REQUEST {
	if { [string tolower [HTTP::uri]] contains "test.aspx" } {
		HTTP::redirect "https://domain2.com/[URI::query [HTTP::uri] account]"
	}
}

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

thank you for the response. I will let you know if it works once I have a chance to test it.

Sorry for slow response. That did work. thank you very much!