Forum Discussion

Santhosh's avatar
Santhosh
Icon for Nimbostratus rankNimbostratus
Apr 06, 2020

Redirect when the client address is not equal to the networks in datagroup

Trying to redirect to the site when the client address is not equal to the datagroup but it's not working. Any help appreciated.

when HTTP_REQUEST {

if { not [matchclass [IP::client_addr] equals XYZ_group } {

  HTTP::respond 301 Location "http://rextrum.com/xyz"

}

12 Replies

  • Hello Santhosh.

     

    Try this code instead:

    if { not [class match [IP::client_addr] contains XYZ_group] } {
        HTTP::respond 301 Location "http://rextrum.com/xyz"
    }

    KR,

    Dario.

    • Santhosh's avatar
      Santhosh
      Icon for Nimbostratus rankNimbostratus

      for some reason it's not liking the contains with in that. So I used equals but it's failing on redirection where it's throwing a error page.

      • Sure, equals is OK.

        when HTTP_REQUEST {
            if { not [class match [IP::client_addr] equals XYZ_group] } {
                HTTP::respond 301 Location "http://example.com/xyz"
            }
        }

        Test it from my lab and it's working fine.

        I think your issue is in your data-group. Could you share the next command output (from TMSH)?

        list ltm data-group internal XYZ_group

        KR,

        Dario.

  • Try this

    -Modify "original_pool" to the default Pool name for the VIP

    when HTTP_REQUEST {
    set host [string tolower [HTTP::host]]
    if {![ class match $host equals XYZ_group ] } {
       HTTP::respond 301 Location "http://rextrum.com/xyz" }
      else 
      { pool original_pool }
    }
  • enable the log and make sure the condition is sucessfull or not

     

    when HTTP_REQUEST {

    if { not[class match [IP::client_addr] equals XYZ_group } {

    log local0. "SUCCESS REDIRECTING THE USER [IP::client_addr] TO NEW DOMAIN "

     HTTP::respond 301 Location "http://rextrum.com/xyz"

    }

    }

     

    in console type tail -f /var/log/ltm to check the log in realtime.

    also use developer tool in browser to check the response .

    • Santhosh's avatar
      Santhosh
      Icon for Nimbostratus rankNimbostratus

      Hi Ragunath,

       

      I can see that in the logs but it's still breaking and when I verified in the developer tools. I don't see any kind of 301 in that.

      • ragunath154's avatar
        ragunath154
        Icon for Cirrostratus rankCirrostratus

        can you post those logs here

         

        also try

         

        HTTP::redirect

         

         

        when HTTP_REQUEST {

        if { not[class match [IP::client_addr] equals XYZ_group } {

        log local0. "SUCCESS REDIRECTING THE USER [IP::client_addr] TO NEW DOMAIN "

         HTTP::redirect "http://rextrum.com/xyz"

        }

        }