Forum Discussion
iRule to redirect to versioned url
Hello,
Need help with iRule. Below is an example of what we are trying to accomplish using iRule. We need F5 to redirect an url to the one that has a version number, by inserting the version number that comes in the header of the request.
Incoming request:
Url- http://xservices.abc.com/security/authentication/login/session/host
Request Headers:
Authorization: 550c2dbe-d3cc-47cf-84ba-b458869799ca
Version: 2.0
F5 should change the url to something like this- http://xservices.abc.com/2.0/securi...ssion/host.
Can you please suggest changes to the below iRule to read the version variable in header successfully?
if { [HTTP::host] eq "xservices.ual.com" } { HTTP::redirect "https:// [HTTP::host]/[HTTP:header Version]/[HTTP:uri] " }
Thank you.
2 Replies
- nitass
Employee
e.g.[root@ve10:Active] config b rule myrule list rule myrule { when HTTP_REQUEST { if { [HTTP::host] eq "xservices.abc.com" and \ [HTTP::uri] eq "/security/authentication/login/session/host" and \ [HTTP::header exists Authorization] and \ [HTTP::header exists Version] } { HTTP::redirect "https://[HTTP::host]/[HTTP::header Version][HTTP::uri]" } } } [root@ve10:Active] config curl -I http://172.28.19.252/security/authentication/login/session/host -H "Host: xservices.abc.com" -H "Authorization: 550c2dbe-d3cc-47cf-84ba-b458869799ca" -H "Version: 2.0" HTTP/1.0 302 Found Location: https://xservices.abc.com/2.0/security/authentication/login/session/host Server: BigIP Connection: Keep-Alive Content-Length: 0 - Nams_119859
Nimbostratus
when HTTP_REQUEST {
if { [HTTP::host] eq "xservicesdev.abc.com" and \
[matchclass [HTTP::uri] starts_with $::xservicesuri] and \
[HTTP::header exists Authorization] and \
[HTTP::header exists Version] } {
HTTP::redirect "http://[HTTP::host]/[HTTP::header Version][HTTP::uri]"
}
}
Thank you. With your help I was able to create the above iRule. This line - [matchclass [HTTP::uri] starts_with $::xservicesuri] checks if the uri starts with some specific service domains (xservicesuri is a list of those names) , this is instead of checking every uri, as we have too many. But this will also require change to the iRule everytime I have new domains. In order to avoid this I would like to check for the uri to "not start with" a version, so something like - not [matchclass [HTTP::uri] starts_with [HTTP::header Version]] but that didnt work. I tried both below:
not [matchclass [HTTP::uri] starts_with $::xservicesuri]
[matchclass [HTTP::uri] not starts_with $::xservicesuri]
Would appreciate any suggestions?
Thank you.
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