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...
Aug 20, 2009
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
}
}
This code will keep the URI intact in the clients browser but change it before it gets to the server.
If you want the browser to stay the same (ie /config) then you should be alls et.
If you want to change the browser, then there's a problem with this approach. The URI is part of the request, not the response. The browser displays the URI that was sent to the server in the initial request. If you want to change the browser, then you'll want to issue a redirect to the client. This will essentially tell the client (browser) to issue a new request to the updated URI.
when HTTP_REQUEST {
if { [HTTP::uri] starts_with "/config" } {
HTTP::redirect "http://[HTTP::host]/main"
}
}
So, hopefully that answers your questions. One last thing to keep in mind is that you are replacing "ALL" requests that start with "/config" to a URI of "/main". So http://server/config1234, http://server/config/a/b, etc. will all map to http://server/main. If you want to retain the original portion of the URI past the "/config" value, then you'll want to do some string replacement (look at the "string map" TCL command for an easy way to do it).
Hope this helps...
-Joe
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
