Forum Discussion
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
serverxx.sub.mysite.com/info_need_to_be_kept
To
mysite.com/nextserver/info_from_above
+ 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:
when
HTTP_REQUEST {
Check if path contains “server”
if { [string tolower [HTTP::path]] contains
"server"}
set serverxx
[getfield [HTTP:host] "." 1]
set uri
[HTTP:uri]
Redirect to mysite.com/nextserver/info_need_to_be_kept
but add the
“serverxx” at the end of the query
HTTP::redirect mysite.com/nextserver/$uri$serverxx
}
The second
iRule needs to change the site back to the original site with the uri
information minus the added serverxx.
I have:
when
HTTP_REQUEST {
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 https://serverxx.sub.mysite.com/info_need_to_be_kept
HTTP::redirect https://$serverxx.sub.mysite.com$uri
if { [HTTP::path] contains "server01"
} {
node 10.10.10.1:80
} elseif [HTTP::path] contains
"server02"}
node 10.10.20.1:80
}
}
else {
pool Server_Pool
}
}
thank you,
mark.
2 Replies
- Patrick_Chang_7Historic F5 AccountI 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 "mysite.com/nextserver/$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). - Mark_57933
Nimbostratus
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.
mark.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
