Forum Discussion
Matt_Mueller_10
Nimbostratus
Dec 22, 2004Help with removing certain header information from URI
Hello,
We're in the initial setup phase, and are having problems with our iRule. This is what we have so far....
Basically, the customer opens a weblink, lets say www.customercenter.com then they add a /webcentral followed by their customer name /customer1. So the entire string would look like:
www.customercenter.com/webcentral/customer1
With this iRule, we're automatically adding a /archibus to the URI, since that is the virtual directory, and the /customer1 is the company name which directs them towards a pool. The following iRule successfully redirects towards a pool, and adds the /archibus, but it also appends the /webcentral/customer1 at the end, so the string which gets sent to the webserver is:
www.customercenter.com/archibus/webcentral/customer1
For the webserver to work, the string it requires is just www.customercenter.com/archibus
What could we do to modify the iRule so that it successfully appends the /archibus, then removes the /webcentral, and also redirects based on whichever /customer gets entered, then removes that /customer from the string as well?
Thanks for any help
when HTTP_REQUEST {
if {( [HTTP::uri] starts_with "/webcentral" ) } {
HTTP::uri "/archibus[HTTP::uri]"
}
if { [HTTP::uri] contains "/customer1" } {
pool customer1
} elseif { [HTTP::uri] contains "/customer2" } {
pool customer2
} else {
pool Supporthomepage
}
}
8 Replies
- There are several ways you can approach this. You could change your code a bit to not do the HTTP rewrite until you have evaluated all of the cases and use a variable to store the pool name like this:
when HTTP_REQUEST { set def_pool "Supporthomepage" if { [HTTP::uri] starts_with "/webcentral" } { if { [HTTP::uri] contains "/customer1" } { set def_pool "customer1" } elseif { [HTTP::uri] contains "/customer2" } { set def_pool "customer2" } HTTP::uri "/archibus" } pool $def_pool }
-Joe - rapmaster_c_127Historic F5 AccountThere's no need for a temporary variable. One thing to note about iRules in 9.x is that they're a full-blown programming language, and the "pool" command is simply that - a command. There's no implied termination of evaluation upon calling it.
That said, the following should work. Note that it rewrites the URI on its way to the server. The client will not see anything different in its browser bar. If you need the client to send a request for a new URI altogether, consider using the HTTP::redirect command instead of rewriting the URI on the fly.rule adsif5 { when HTTP_REQUEST { if {[HTTP::uri] contains "/customer1"} { pool customer1 } elseif {[HTTP::uri] contains "/customer2"} { pool customer2 } else { pool Supporthomepage return } if {[HTTP::uri] starts_with "/webcentral"} { HTTP::uri "/archibus" } } } - Matt_Mueller_10
Nimbostratus
Thanks Joe and Raja for the responses.
I tried the rule by Rapmaster_c, but it doesn't do exactly as I would expect.
If I type in http://192.168.150.225/webcentral/customer1, it returns a value of http://192.168.150.225/archibus to my webbrowser and I am NOT redirected to a webpool. The webpool consists of Tomcat servers, and the 404 error is not from the Tomcat server. If I type in http://192.168.150.225/customer1, I get redirected correctly to the Tomcat server pool as I would expect, however, I do not get to the correct subdirectories in the pool, as it tries then to go to a subdirectory called "customer1" instead of "archibus".
Does anyone have any ideas? - Matt_Mueller_10
Nimbostratus
Just wanted to clarify from last post. Does anyone have any ideas as to why when I enter http;//192.168.150.225/webcentral/customer1 does it not redirect to the pool apparently, but when I type http://192.168.150.225/customer1 it does? Apologies for being a little slow on the uptake here... - drteeth_127330Historic F5 AccountI tested the rule from rapmaster_c and it seems to work fine for me. I recommend using the log command to log the original [HTTP::uri]. Is there any chance that the customer name is part of the querystring?
- Matt_Mueller_10
Nimbostratus
Dr Teeth,
I am not familiar at all with the logging capabilities on the BigIP, do I have to turn that on from the command line console? I looked under logging under the gui web page interface, but wasn't sure what to do here. Could you please elaborate on where to do this? The BIGIP is on 9.0.2 OS.
If I do have to enable it from command line, how would I retrieve the log?
THanks - bl0ndie_127134Historic F5 AccountYou can log directly from iRule without any change in the gui. Please refer to the following syntax and example.
log [.]
Available logging levels"alert" "crit" "debug" "emerg" "err" "info" "warning"
Available logging facility"user" "syslog" "local0" "local1" "local2" "local3" "local4" "local5" "local6" "local7" "uucp" "authpriv", "cron" "daemon" "ftp" "kern" "lpr" "mail" "mark" "news" "ntp" "security"
Examplelog local0.info
Please note that these messages end up as entries in /var/log/ltm or as specified by /etc/syslog.conf. - Matt_Mueller_10
Nimbostratus
when HTTP_REQUEST { if {[HTTP::uri] contains "/customer1"} { pool Customer114.i } elseif {[HTTP::uri] contains "/customer2"} { pool Customer214.i } else { pool Defaulthomepage return } if {[HTTP::uri] starts_with "/webcentral"} { HTTP::uri "/archibus" } log local0.info }
Please note the rule as I currently have it configured, also the log line. Is that correct? I tried placing the log line outside of the when HTTP_REQUEST brackets, but it said invalid command.
I apologize, but I have no idea where you mean by the following location, can I get to this in the web gui?
"Please note that these messages end up as entries in /var/log/ltm or as specified by /etc/syslog.conf."
Again to explain our setup, the customer would type in http://192.168.150.225/webcentral/customer1
Based on the iRule, the BIGIP would turn around and go to this address:
http://192.168.150.214/archibus
thanks for your help
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects
