Forum Discussion

MohanK's avatar
MohanK
Icon for Altostratus rankAltostratus
Oct 16, 2020

iRule for redirecting the traffic of GoogleBot to a different pool using X-Header Value

We need to redirect Google Bots traffic to another Pool, What is the effective and simple iRule I can use to accomplish that ?

We can filter the traffic using X-Header Value, which is set to value "8" are good to redirect to a new pool.

 

Does Below iRule Work ?

 

when HTTP_REQUEST { 

if { [matchclass [string tolower [HTTP::header X-forwarded-for]] equals 8] } { 

pool A 

pool default

 }

 

OR

 

when HTTP_REQUEST { 

if { [matchclass [string tolower [HTTP::header User-Agent]] contains googlebot] } { 

pool A 

pool default

 }

3 Replies

  • Hi MohanK,

    when HTTP_REQUEST {
    	if { [HTTP::header X-Forwarded-For] equals "8" && [string tolower [HTTP::header User-Agent]] contains "googlebot" } { 
    		pool A 
    	}
    	else {
    		pool default
    	}
    }
  • JP_G's avatar
    JP_G
    Icon for Altostratus rankAltostratus

    Hello All,

     

    I am looking to refine the rule proposed above just a bit and came up with the following:

    ---

     

    when HTTP_REQUEST {

    if { [HTTP::header exists X-APP-WHITELIST] and [HTTP::header X-APP-WHITELIST] equals "8" or [string tolower [HTTP::header User-Agent]] contains "googlebot" } {

    pool A

    else {

    pool default

    }

    }

     

    ---

    We are looking for the detail: "X-APP-WHITELIST" in the header equal to "8" OR if the user-agent has, "googlebot" discovered in the header. Not looking at the XFF part of the header. The, '&&' appears to be a logical AND in which both conditions have to be true. We are looking for one or the other; does not have to be both.

     

    Does this look to be simpler? 

     

    Thank you all for your replies.

  • Thank you for restructuring my iRule Eaa, I'll apply the above rule and let you know, if that works.