Forum Discussion

Sanal_Babu's avatar
Sanal_Babu
Icon for Nimbostratus rankNimbostratus
Apr 22, 2023
Solved

Redirect all request except few path

Hi ,

I am lookin for an irule which should redirect all request to a URL except few based on below path.

/en/services/
/en/ajax/logout
/en/e-service-errors

All the request should redirected to https://stg.bbbb.com except the above ones.

Please note the URL https://stg.bbbb.com is configured in a different site not in the same F5 load balancer.

Tried lot of irule's but no luck. All the requests are redirecting to the new sites.

Please help.

  • Sanal_Babu Assuming the default pool that you would like to forward traffic to is associated to this virtual server the following iRule should do what you are looking for.

    when CLIENT_ACCEPTED priority 500 {
    
        set DEFAULT_POOL [LB::server pool]
    
    }
    
    when HTTP_REQUEST priority 500 {
    
        set URI [string tolower [HTTP::uri]]
    
        switch -- ${URI} {
            /en/services/ -
            /en/ajax/logout -
            /en/e-service-errors {
                pool ${DEFAULT_POOL}
            }
            default {
                HTTP::redirect "https://stg.bbbb.com"
            }
        }
    
    }

2 Replies

  • Sanal_Babu Assuming the default pool that you would like to forward traffic to is associated to this virtual server the following iRule should do what you are looking for.

    when CLIENT_ACCEPTED priority 500 {
    
        set DEFAULT_POOL [LB::server pool]
    
    }
    
    when HTTP_REQUEST priority 500 {
    
        set URI [string tolower [HTTP::uri]]
    
        switch -- ${URI} {
            /en/services/ -
            /en/ajax/logout -
            /en/e-service-errors {
                pool ${DEFAULT_POOL}
            }
            default {
                HTTP::redirect "https://stg.bbbb.com"
            }
        }
    
    }
  • Hi, 

    Have you tried this example yet? https://my.f5.com/manage/s/article/K15117465 

    You may need to play a little bit with the ones you do/don't want to redirect, but should do the trick. 

    Alternatively, have you tried creating this under Local Traffic Policies? That will be able to do it as well, and should be a lot quicker to build. (more info: https://techdocs.f5.com/en-us/bigip-15-1-0/big-ip-local-traffic-management-getting-started-with-policies.html

    Hope this helps,