Forum Discussion
Can someone tell me teh meaning for the Irule and how to write similar ones?
when HTTP_REQUEST { set CID [findstr [string tolower [HTTP::uri]] "clientid=" 9] if { [class match [string tolower [HTTP::uri]] contains itemCodes_int4] } { set redirect_location [class match -value [string tolower [HTTP::uri]] contains itemCodes_int4] if {$redirect_location ne "" and $CID ne ""} { HTTP::redirect "https://$redirect_location/app/home?clientId=$CID" log local0. "1. [IP::client_addr] requested [HTTP::uri] sent to https://$redirect_location/app/home?clientId=$CID" } elseif { $redirect_location ne "" and $CID eq "" } { HTTP::redirect "https://$redirect_location" log local0. "2. [IP::client_addr] requested [HTTP::uri] sent to https://$redirect_location" } unset redirect_location CID } }
2 Replies
- John_Alam_45640Historic F5 Account
The irule parses the CLIENTID from the URI parameters. Then it looks up the uri in a datagroup called itemCodes_int4.
If URI is found in datagroup, grab value associated with that URI, (redirection location).
If URI is found and its associated redirection location is also not empty, and the CLIENTID was found redirect user to found redirection location with CLIENTID attached.
If URI is found and its associated redirection location is also not empty, but CLIENTID not found, send user to new redirection location without a CLIENTID.
In both cases it logs who was redirected and where to in the /var/log/ltm file.
Here is the irule properly posted:
when HTTP_REQUEST { set CID [findstr [string tolower [HTTP::uri]] "clientid=" 9] if { [class match [string tolower [HTTP::uri]] contains itemCodes_int4] } { set redirect_location [class match -value [string tolower [HTTP::uri]] contains itemCodes_int4] if {$redirect_location ne "" and $CID ne ""} { HTTP::redirect "https://$redirect_location/app/home?clientId=$CID" log local0. "1. [IP::client_addr] requested [HTTP::uri] sent to https://$redirect_location/app/home?clientId=$CID" } elseif { $redirect_location ne "" and $CID eq "" } { HTTP::redirect "https://$redirect_location" log local0. "2. [IP::client_addr] requested [HTTP::uri] sent to https://$redirect_location" } unset redirect_location CID } }HTH
- dipta_03_149731
Nimbostratus
I have one more query. Right now for a virtual , I have 2 irules, On efor inserting remote client ip and another is the above one. Now i got a request to do a redirection from port 80 to 443 and strip www from the http://www.xyz.com/ url. So if I have 4 Irules on a virtual , will it take too much processing time?
Secondly to strip www from a http request can i use below irule:
when HTTP_REQUEST { if {[string tolower [HTTP::host]] starts_with "www."}{ HTTP::respond 301 "https://[string range [HTTP::host] 4 end][HTTP::uri]" } Else {HTTP::respond 301 "https://[HTTP::host][HTTP::uri]"} }
Is there any constraint for using 301 in http version 1.1?
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