Showing results for 
Search instead for 
Did you mean: 

Redirect to new URL, but keep certain part of the original URI path.


Hi All,


Can you guys help with this unique requirement? We need to match based on the URI the client comes in on (IAM), than redirect to a new URL while

changing IAM to IAM2, and keeping their unique URI hash...


Thanks for your help in advance!


when HTTP_REQUEST {     if { [string tolower [HTTP::host]] equals "" and [string tolower [HTTP::uri]] starts_with "/IAM/" } {         set temp_uri [HTTP::uri]        HTTP::respond 307 Location "$temp_uri"   } }





  1. match URI "/IAM" on the original URL
  2. Redirect the user to a new URL, however change the URI "IAM" to "IAM2" while taking the dynamic generated URI hash using the "set temp_uri"

and appending this to the new redirected to URL...

so basically anything after IDP should be carried over to the new URL as this is dynamically generated and can change. We need this...





Original URL-->


New Redirect to -> Should redirect to



The issue with the code above is that when we try this, the final redirect URL also appends the orginal "IAM" into the URL string. Is there a way to not do that and only add this and also keep anything after the "/IDP/SSO.saml2?......." as this is dynamic?



It adds the "IAM" as you can see below.....




Hi ant77,

when HTTP_REQUEST { if { [HTTP::host] equals "" and [HTTP::uri] starts_with "/IAM/" } { set temp_uri [string map {/IAM/ /IAM2/} [HTTP::uri]] HTTP::respond 307 Location "$temp_uri" } }


This works! Thank you very much Enes Afsin Al...

Appreciate your help!


Ok here is a strange thing and it is not working with HTTPS...

I tried the modification tonight and it works on a HTTP Virtual server, however when I tried the same iRule on an HTTPS VIP, it does not work.

Do you know what is happening? or is the URI string mapping not working with HTTPS? Is it possible the F5 can't read the URI (IAM) in the path and can't change the URI to IAM2 and redirect because of that? Do I need to do anything or consolidate the two if statement together?


The bottom one works if you direct go to, but for some reason it does not like the matching of IAM to IAM2....what could be the issue?


Thanks for your help.


when HTTP_REQUEST { if { [HTTP::host] equals "" and [HTTP::uri] starts_with "/IAM/" } { set temp_uri [string map {/IAM/ /IAM2/} [HTTP::uri]] HTTP::respond 307 Location "$temp_uri" } log local0. "Host [HTTP::host] --> URI [HTTP::uri] -->Redirected"   if { [HTTP::host] equals "" } { set temp_uri [HTTP::uri] HTTP::respond 307 Location "$temp_uri" log local0. "Host [HTTP::host] --> URI [HTTP::uri] -->Redirected" } }


I think two if matching cause this. Can you try this?

when HTTP_REQUEST { if { [HTTP::host] equals "" } { #log local0. "Host [HTTP::host] --> URI [HTTP::uri] --> Redirected" if { [HTTP::uri] starts_with "/IAM/" } { HTTP::respond 307 Location "[string map {/IAM/ /IAM2/} [HTTP::uri]]" return } else { HTTP::respond 307 Location "[HTTP::uri]" return } } }


Enes Afsin Al, Thank you so much! I will try tonight and let you know...