Showing results for 
Search instead for 
Did you mean: 

iRule that match rewrite policy


Hi guys,


I need to implement an iRule that works like a Rewrite profile but should change URI path (remove a part of the string) to the server side. I cannot use the normal rewrite because on the same VIP I’ve two domains and the server URI it’s the same for both, this is an example: -> should rewrite to /service1 when goes to server pool -> should rewrite to /service1 when goes to server pool


obviously the policy gives me error backup server URI is already used.


I’ve tried this iRule but I got error 404 from server side:



  set host [HTTP::host]

  set uri [string tolower [HTTP::uri]]


  if { $host equals "" } {

    HTTP::uri [string map {"/test" "" } $uri ]




any help is really appreciated




F5 Employee
F5 Employee

Your iRule looks like it is only covering one of the two possible host names - There is no condition for removing the "/prod" string if the host name is which may be the cause of your 404 response. You can add a couple of log commands to the iRule to see what the before and after URIs look like. For example:

when HTTP_REQUEST { log local0. "URI on client side is: [HTTP::uri]" if { [HTTP::host] equals "" || [HTTP::host] equals "" } { HTTP::uri [string map { "/test" "" } [HTTP::uri] ] log local0. "URI on server side changed to: [HTTP::uri]" } }

Also, if there is any chance the URI might contain only "/test" or "/prod" (e.g. "" or "") you should check for that possibility before executing the string map command as shown. Otherwise, it will leave you with a null URI which generates an error message to /var/log/ltm and stops the iRule from completing.