iRule to change the URL hostname and path, but nothing else

I need to write an iRule that will redirect the browser from this:

http://server1/fubarpath/AMSDocViewer.asp?DocID=626527942&Rev=1

to this:

http://server2/apppath/ImageEnablingLauncher.aspx?DocID=626527942&Rev=1

The main point is that I need to retain the ? character and everything to the right of it.

[HTTP::uri] seems to be important here, that grabs everything after the hostname. I only need part of that. “string map” could maybe be used to provide a list of things to be changed in the URL, thus keeping the part I need to keep, but I don’t know how to put it all together.

HTTP::path

and

HTTP::query

are your friends

DevCentral - An F5 Technical Community DevCentral - An F5 Technical Community

Try this:

when HTTP_REQUEST {
    if {([HTTP::path] equals "/fubarpath/AMSDocViewer.asp") && ([HTTP::host] equals "server1")} {
        HTTP::respond 302 noserver Location "http://server2/apppath/ImageEnablingLauncher.aspx?[HTTP::query]"
    }
}