iRule Question

Hi Experts,

I have an iRule that looks like this which is applied to a Virtual Server that listens on port 8080.

when HTTP_REQUEST {
   HTTP::redirect http://[getfield [HTTP::host] ":" 1][HTTP::uri]

}

But for some reason this is not getting redirected to port 80 virtual server as I expected. Can anyone check why this is not working?

Logging is your friend Krishna.

when HTTP_REQUEST {
   HTTP::redirect http://[getfield [HTTP::host] ":" 1][HTTP::uri]
   log local0. "Redirected http://[getfield [HTTP::host] ":" 1][HTTP::uri]"
}

Then goto System → Logs and search for “redirected” to see what the redirects actually look like. This may give you a clue as to the problem.

This works perfectly on my test system. Adding a log line as Kevin suggests:

log local0. "Rewriting [HTTP::host] to [getfield [HTTP::host] ":" 1]"
 Result:
Oct 13 16:16:42 ltm3 info tmm[48128]: Rule /Common/redirectest : Rewriting 192.168.102.62:8080 to 192.168.102.62

From the tcp stream in my wireshark capture, you can see the Host with the 8080 port, the rewritten Location header without, and the subsequent request to port 80:

GET / HTTP/1.1
Host: 192.168.102.62:8080
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:55.0) Gecko/20100101 Firefox/55.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Upgrade-Insecure-Requests: 1

HTTP/1.0 302 Found
Location: http://192.168.102.62/
Server: BigIP
Connection: Keep-Alive
Content-Length: 0    

GET / HTTP/1.1
Host: 192.168.102.62
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:55.0) Gecko/20100101 Firefox/55.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Upgrade-Insecure-Requests: 1