when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "site2.lab.com" } { HTTP::respond 302 noserver -reset Connection close Location http://site3.lab.com } }
With the above iRule, the initial connection to site2.lab.com is closed when the redirect message is sent to the client. Check out the below output from curl which validates the same.
shoaib@ubnsrv01:~$ curl -ivL http://site2.lab.com * Rebuilt URL to: http://site2.lab.com/ * Trying 64.25.36.20... * Connected to site2.lab.com (64.25.36.20) port 80 (#0) > GET / HTTP/1.1 > Host: site2.lab.com > User-Agent: curl/7.47.0 > Accept: */* > * HTTP 1.0, assume close after body < HTTP/1.0 302 Found HTTP/1.0 302 Found < Location: http://site3.lab.com Location: http://site3.lab.com < Connection: close Connection: close < Content-Length: 0 Content-Length: 0 < * Closing connection 0 * Issue another request to this URL: 'http://site3.lab.com' * Rebuilt URL to: http://site3.lab.com/ * Trying 64.25.36.30... * Connected to site3.lab.com (64.25.36.30) port 80 (#1) > GET / HTTP/1.0 > Host: site3.lab.com > User-Agent: curl/7.47.0 > Accept: */* > < HTTP/1.1 200 OK HTTP/1.1 200 OK < Content-Type: text/html Content-Type: text/html < Last-Modified: Thu, 17 Aug 2017 21:14:18 GMT Last-Modified: Thu, 17 Aug 2017 21:14:18 GMT < Accept-Ranges: bytes Accept-Ranges: bytes < ETag: "40d9a1c99d17d31:0" ETag: "40d9a1c99d17d31:0" < Server: Microsoft-IIS/7.5 Server: Microsoft-IIS/7.5 < Date: Sat, 28 Oct 2017 19:54:47 GMT Date: Sat, 28 Oct 2017 19:54:47 GMT < Connection: close Connection: close < Content-Length: 191 Content-Length: 191 < <html> <head> <style> body { background-color: ffcc99 } </style> </head> <body> <h1 style="font-size:300%;text-align:center;">site3.lab.com on dc1-win-srv02</h1> </body> * Closing connection 1 </html>shoaib@ubnsrv01:~$