Duplicate URI redirection issue

URI redirection issue

we have URI redirection configured as below Internet URL- https://www.abcd.com/test/xyz Intranet URL-

Internet URL- https://www.abcd.com/testhij/xyz Intranet URL-

Along with this, we have client source IP based restriction at “/testhij/xyz”

As shown above since “xyz” URI exists in both URLs.

iRule1 used is as below when HTTP_REQUEST {set newuri [class match -value [HTTP::uri] equals DATAGROUP-REDIRECT ]} iRule2 used is as below

switch -glob [string tolower [HTTP::uri]] { “/xyz" { pool XYZ_pool } "/xyz” { if { [class match $forwarded_ip equals WIFI ] } { Process the traffic pool HIJ-Pool } else { drop

}

Datagroup “DATAGROUP-REDIRECT” defines

STRING: /testhij/xyz VALUE :/xyz

and

STRING: /test/xyz

VALUE :/xyz

Since URI “/xyz” is exist in both the request, we are not getting expected output.

Is there anyway, we can make it working ? Appreciate in advance.

  1. Please post again the code here with right format (select the whole code and press TAB key, look in the Preview below the text if it is readable)
  2. We can’t read in your head, can you please explain with examples what is the expected output and :wink:
  3. Why are you configuring 2 different irules instead of a merged code?

URI redirection issue we have URI redirection configured as below Internet URL- https://www.abcd.com/test/xyz Intranet URL- Internet URL- https://www.abcd.com/testhij/xyz Intranet URL- Along with this, we have client source IP based restriction at “/testhij/xyz” As shown above since “xyz” URI exists in both URLs.

iRule1 used is as below

2. Set host as will be used to rewrite hardcoded http redirection links
set host [HTTP::host]
if { [HTTP::uri] equals "/" } {
 HTTP::uri "/reb/"
}
set newuri [class match -value [HTTP::uri] equals dg_redirect ]
  log local0.info "uri is [HTTP::uri]"
 if {$newuri ne ""} {
 HTTP::respond 302 Location "https://[HTTP::host]$newuri" Connection Close
    TCP::close
    event disable
    log local0. "[HTTP::uri] redirected to $newuri"
    unset newuri
   }

} iRule2 used is as below

when HTTP_REQUEST {
     "bypass" tracks whether or not we made any changes inbound so we
     can skip changes on the outbound traffic for greater efficiency.
    set bypass 1

     Initialize other local variables used in this rule
    set orig_uri "[HTTP::uri]"
    set orig_host "[HTTP::host]"
    set log_prefix "VS=[virtual name], Host=$orig_host, URI=$orig_uri"
set clientside ""
set serverside ""
set newpool ""
set ppass ""
Source_IP_Detection_Option_28_Start
    if { [IP::version] == 4 } {
            set OPTION_28_IP [TCP::option get 28]
            if {[string length $OPTION_28_IP] > 0 } {
                    set forwarded_ip [IP::addr parse $OPTION_28_IP 0]
                    log local0. "IP Found in TCP Option 28: $OPTION_28_IP"
            } else {
                    log local0. "Length Error in TCP Option 28 raw value: $OPTION_28_IP"
            }
    }
    log local0. "URI = [string tolower [HTTP::uri]]"
    log local0. "Client IP SNAT = [IP::client_addr]"
    log local0. "Client IP = $forwarded_ip"
Source_IP_Detection_Option_28_Stop
if {! [class exists $clname]} {
    log local0. "$log_prefix: Data group $clname not found, exiting."
            pool $default_pool
    return
} else {
    set ppass [class match -element "$orig_host$orig_uri" starts_with $clname]
    if {$ppass eq ""} {
         Did not find with hostname, look for just path
        set ppass [class match -element "$orig_uri" starts_with $clname]
        }
    if {$ppass eq ""} {
             No entries found
            if { $static::ProxyDebug > 0 } {
log local0. "$log_prefix: No rule found, using default pool $default_pool       and exiting"  
            }
            switch -glob [string tolower [HTTP::uri]] {
                                     "/xyz*" { pool xyz_pool }
                 "/xyz*" { 
if { [class match $forwarded_ip equals WIFI ] }
Process the traffic
pool xyzhij_pool 
   } else {
Drop Connection
HTTP::respond 200 content "Apology   PageAccess Denied"
 log local0. "Non wifi IP detected and connection dropped"
Pool xyzhij_pool
                }

====================================

From internet if URL requested as https://www.abcd.com/test/xyz, it should redirect to https://www.abcd.com/xyz and it should reach to so that it will be processed properly.

From internet if URL requested as https://www.abcd.com/testhij/xyz and if it is coming from specific source IPs then only it should get redirected to https://www.abcd.com/xyz and it should reach to so that it will be processed

In current scenario, since /xyz is overlapping, I would like overcome this overlapping