Forum Discussion

Mark_57933's avatar
Icon for Nimbostratus rankNimbostratus
Sep 27, 2011

2 iRules - HTTP rewrites keeping info from rule to rule

Hi:- these are the first iRules i am trying to write.


I need to write 2 IRules the need to reference the same information theough different conversations.


the first needs to redirect a URL t oa new site but keep the original serverxx information. serverxx will be one of up to 16 servers so xx will be server01, server02... server16. For brevity i have only added two servers to the second iRule.




I need to change the URL of the initial conversation from


To + serverxx


The nextserver site does not reference the URI query information so I can add the serverxx to the end of the query.



I have this iRule:







Check if path contains “server”


if { [string tolower [HTTP::path]] contains "server"}


set serverxx [getfield [HTTP:host] "." 1]


set uri [HTTP:uri]




Redirect to


but add the “serverxx” at the end of the query










The second iRule needs to change the site back to the original site with the uri information minus the added serverxx.


I have:






Check if uri query contains the word nextserver if it does then get the word server + 2 characters from the end of the uri


if { [string tolower [HTTP::query]] contains "server"}


set serverxx [string range [HTTP:query] server 0 8]


set uri [findstr [HTTP:uri] nextserver server]



Redirect to




HTTP::redirect https://$$uri



if { [HTTP::path] contains "server01" } {




} elseif [HTTP::path] contains "server02"}








else {


pool Server_Pool








thank you,







2 Replies

  • Patrick_Chang_7's avatar
    Historic F5 Account
    I believe your first iRule will do what you wish, but it looks like you are trying to add the serverxx as a query. If this is the case, you will need to insert a "?" like the following


    HTTP::redirect "$uri\?$serverxx"


    Then, your 2nd iRule should work. However, if the original URI already contains a query (i.e a "?" followed by other text), then this will not work. If you could insert the $serverxx as a query parameter, is serverxx=$serverxx, you could just check for that in the 2nd iRule and it would always work. One would have to search in the first iRule to insert the query parameter differently if the original URI already contains query parameters. ?serverxx=$serverxx if there is no query parameter and ,serverxx=$serverxx if there is already a query parameter(s).



  • Hi Patrick,


    Thanks for the reply.


    I think i need to change the first rule to a stream filter as i need to send the hyperlink to the client before they click the link.


    I will then try to add a cookie and get information from the cookie on the second pass and rewrite from there.



    thanks for your time but i think i have a bit more white boarding to do on this.