Rewrite HTTP Redirect Port

Problem this snippet solves:

Intercepts server-set redirect responses & removes the server's port from the Location header.

Code :


   # Check if server response is a redirect
   if { [HTTP::header is_redirect]} {

      # Log original and updated values
      log local0. "Original Location header value: [HTTP::header value Location],\
         updated: [string map ":[TCP::remote_port]/ /" [HTTP::header value Location]]"

      # Do the update, replacing :8080/ with / (where 8080 is the pool member's port)
      HTTP::header replace Location [string map ":[TCP::remote_port]/ /" [HTTP::header value Location]]

# Note: You could replace the current mapping, ":[TCP::remote_port]/ /", with the VIP port if the virtual server is on a non-standard port:

# Replace selected pool member's port with the VIP port
HTTP::header replace Location [string map ":[LB::server port]/ :[clientside {TCP::local_port}]/" [HTTP::header value Location]]
Published Mar 18, 2015
Version 1.0

Was this article helpful?


  • I have a similar situation, but the redirects are immediately sends redirect to If I create a custom http profile, chose the 'All' choice on the 'Rewrite redirects' option and associate it to the virtual server it fixes the port on the redirect, but it also changes the protocol to https. I thought I would check out fixing this with an iRule since the test developer wants to keep the dev instance http. I will try this code snippet - thanks Aaron!
  • Did exactly what I was looking for. Same situation as Steve above. Thanks!