Forum Discussion

Blue_whale's avatar
Blue_whale
Icon for Cirrocumulus rankCirrocumulus
Jan 24, 2020

[URGENT] - Need help on Irule for URL/URI redirect

We want all the request comming to www.example.fr from specific source 10.10.10.1 to get redirected to www.example.fr/ckpartner/ and this should be logged . 

 

 

 

 

Can you please with the below Irule we can achieve this ? Or any modification is required for this .

 

 

 

when HTTP_REQUEST {

 

if { ([IP::addr [IP::client_addr] equals 10.10.10.1]) && ([HTTP::host] starts_with "www.example.fr") } {

 

log local0.

 

set newUri [string map {"/" "ckpartner/"} [HTTP::uri]]

 

HTTP::uri $newUri

 

}

 

}

4 Replies

  • You can try something like this:

    when HTTP_REQUEST {
       if { ([HTTP::host] equals "www.example.fr") } {
           HTTP::redirect "www.example.fr/ckpartner"
           log local0. "Client IP [IP::client_addr] has been redirected"
         }
    }
    • Blue_whale's avatar
      Blue_whale
      Icon for Cirrocumulus rankCirrocumulus

      Thanks Rodrigo ,

       

      This Irule should only redirect when external users are trying to access the VIP , So we don't want this to impact the internal clients ...So we want to redirect only when we see request from specific external clients .

  • Then you can use a class match function along with a data group to define your external IP ranges you want redirected.

    Something like this:

    when HTTP_REQUEST {
       if { ([HTTP::host] equals "www.example.fr") and [class match [IP::client_addr] equals "specific_external_client_range_data_group"] } {
           HTTP::redirect "www.example.fr/ckpartner"
           log local0. "Client IP [IP::client_addr] has been redirected"
         }
    }

    To create a data group you can use tmsh create /ltm data-group...

    I'd also advise you to look into LTM policies as they might be more efficient.

    Please, test it first 🙂

    • Blue_whale's avatar
      Blue_whale
      Icon for Cirrocumulus rankCirrocumulus

      Thanks for your help ,

       

      My requirement is currently working with below Irule but I would like to add Datagroup to below Irule so that I can filter more external IP's

      Could you please help me modify this irule .

      I tried but I got error "variable reference required preeciding $"

       

       

       

      when HTTP_REQUEST {

      if {

                       ([IP::client_addr] contains "10.10.10.1%70") && ([string tolower [HTTP::uri]] contains "/cklauncher/")

                                        }

                                                     {

                      drop

      }                                                             

      elseif { [string tolower [HTTP::path]] equals "/" && ( [IP::addr [IP::client_addr] equals 10.10.10.1%70]) } {

      # redirect the request

      log local0. "issuing redirect request to [HTTP::host][HTTP::uri] from [IP::client_addr]"

      HTTP::redirect https://[getfield [HTTP::host] ":" 1]/ckpartner/

      }

      }