Forum Discussion
Nicola_DT
Nimbostratus
Aug 20, 2009irule for rewriting an uri in an http request
Hi everyone,
I am writing a simple irule so that if an http request will arrive on the virtual with an uri that starts with "/config" the request will be passed to the pool rewrited and the url "/config" must be replaced by "/main".
The irule 'should' work:
when HTTP_REQUEST {
if {[HTTP::uri] starts_with "/config"} {
set HTTP::uri /main
}
}
Issus is I do not know if the Bigip has to re-substitute the uri in the response to the client, for that I'd add something like:
when HTTP_RESPONSE
if { [HTTP::uri] starts_with "/main" } {
set HTTP::uri /config}
}
But this second part of the irule gives me errors:
01070151:3: Rule [aaa] error:
line 1: [wrong args] [when HTTP_RESPONSE ]
line 3: [command is not valid in the current scope] [if { [HTTP::uri] starts_with "/main" } {
set HTTP::uri /config} ]
line 7: [command is not valid in the current scope] [}]
Any Tip on how to fix this easy uri rewriting issue ?
Thanx,
Nicola.
- The_Bhattman
Nimbostratus
I think the first irule event was more correct, but needs a monitor tweak.when HTTP_REQUEST { if {[HTTP::uri] starts_with "/config"} { HTTP::uri /main } }
when HTTP_REQUEST { if {[HTTP::uri] starts_with "/config"} { HTTP::redirect http://[HTTP::host]/main } }
- The "HTTP::uri" is a command with muliple purposes. If you don't supply a parameter, it retrieves the value. If you give it a uri, then it will set the value. You need to remove your "set" command like this:
when HTTP_REQUEST { if { [HTTP::uri] starts_with "/config"} { HTTP::uri /main } }
when HTTP_REQUEST { if { [HTTP::uri] starts_with "/config" } { HTTP::redirect "http://[HTTP::host]/main" } }
- Typed too slow. Looks like cmbhatt beat me to the punch!
- Nicola_DT
Nimbostratus
Thanx for the tips, - hoolio
Cirrostratus
The command names are case sensitive, so it should be HTTP::uri. - hoolio
Cirrostratus
The value for HTTP::uri is cached within the same event and event priority. If you want to see the effect of the change, you can add a second HTTP_REQUEST event that runs after your change is made with a log statement. Once you're okay with the test, you can comment out/remove the debug event.when HTTP_REQUEST priority 501 { log local0. "[IP::client_addr]:[TCP::client_port] (501): \[HTTP::uri\]: [HTTP::uri]" }
- Nicola_DT
Nimbostratus
Nice m8
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