Technical Forum
Ask questions. Discover Answers.
cancel
Showing results for 
Search instead for 
Did you mean: 

IRULE - redirect URI

SV2022
Nimbostratus
Nimbostratus

my requiremnet is if URI is something like /business/car/truck it shoud look for the "business " and change it as /company/car/truck..

$Path_proxy= company

when HTTP_REQUEST {
set http_hostname [getfield [HTTP::host] : 1]
set name [class match -value -- $http_hostname equals /DG_Test_i]
set lname [class match -value -- $Envname equals /DG_Test_i]
set proxy [class match -value -- $Poolname equals /DG_Test_i]
log local0. " name is $name "
log local0. " lname is $lname "
log local0. " proxy is $proxy "
if { [HTTP::uri] starts_with "/business"} {
HTTP::uri [string map {"/bsuiness/" $Path_proxy}[HTTP::uri]]------------->NOT working (path_proxy = /company)
HTTP::uri [string map {"/bsuiness/" "/company"}[HTTP::uri]]------------->working
}
}

 

verified with logs ..proxy variable  is assigned with value "/company" 

when i use direct content its working as expected whereas when i call the same value with variable($proxy) its not working.

 

1 ACCEPTED SOLUTION

Kevin_Stewart
F5 Employee
F5 Employee

Is this more or less what you're iRule looks like?

when HTTP_REQUEST {
   set Path_proxy "/company/"

   set http_hostname [getfield [HTTP::host] : 1]
   set name [class match -value -- $http_hostname equals /DG_Test_i]
   set lname [class match -value -- $Envname equals /DG_Test_i]
   set proxy [class match -value -- $Poolname equals /DG_Test_i]

   log local0. " name is $name "
   log local0. " lname is $lname "
   log local0. " proxy is $proxy "

   if { [HTTP::uri] starts_with "/business" } {
      HTTP::uri [string map [list "/business/" ${Path_proxy}] [HTTP::uri]]
   }
}

View solution in original post

6 REPLIES 6

Kevin_Stewart
F5 Employee
F5 Employee

Try the string map with a list instead:

HTTP::uri [string map [list "/business/" ${Path_proxy}] [HTTP::uri]]

Hi kevin,

its not accepting the arguments

error: [wrong # args][string map [list "/business" ${Path_proxy}][HTTP::uri]]
/common/Test_api:13: error: [command is not valid in the current scope][}]

Kevin_Stewart
F5 Employee
F5 Employee

Is this more or less what you're iRule looks like?

when HTTP_REQUEST {
   set Path_proxy "/company/"

   set http_hostname [getfield [HTTP::host] : 1]
   set name [class match -value -- $http_hostname equals /DG_Test_i]
   set lname [class match -value -- $Envname equals /DG_Test_i]
   set proxy [class match -value -- $Poolname equals /DG_Test_i]

   log local0. " name is $name "
   log local0. " lname is $lname "
   log local0. " proxy is $proxy "

   if { [HTTP::uri] starts_with "/business" } {
      HTTP::uri [string map [list "/business/" ${Path_proxy}] [HTTP::uri]]
   }
}

Great!! it was some spacing issues.Below worked

HTTP::uri [string map [list "/business/" ${Path_proxy}] [HTTP::uri]]

But earlier when i directly mention the /company it was not visible in address bar,but now when using the variable its visible in address bar..so how to make sure that the user does not see the new instance in address bar...

You might want to do a browser developer tools capture or cURL test to see if the server isn't actually redirecting the client to this new URL. The iRule is changing the HTTP uri on the way to the server, otherwise the client should never know about this change. If you do a developer tools capture in the browser, look for a 30x redirect to this new URL path.

everything works fine...Thanks!!!..not sure why address bar was showing the modified URI initially but it got fixed automatically .