Forum Discussion

Jean_42123's avatar
Jean_42123
Icon for Nimbostratus rankNimbostratus
Mar 06, 2011

i-rule for HTTP header based on the Accept-Language

Hi Guys,

 

 

Is it possible to write an i-rule to check the HTTP headers based on the "Accept-Language" field.

 

 

 

thanks in advance.

 

 

 

Jean

 

  • You can certainly write a rule to look for a certain string within that header. Is there something specific you're trying to accomplish?
  • Hi Chris,

     

     

    In Accept_Language field we are getting following two different valuse based on Mobile handset language. They are

     

     

    Accept-Language: ar\r\n (When handset language is Arabic)

     

    Accept-Language: en;q=1.0,fr;q=0.5,ar;q=0.5\r\n (When handset language is English)

     

     

    We want to redirect the URL to other sub URL based on language field. If it is Arabic then to arabic page else to english page.

     

     

    I have written the following iRule.

     

     

    rule myword_new

     

    {

     

    when HTTP_REQUEST

     

    {

     

    if {[HTTP::uri]=="/" or [HTTP::uri]==""}

     

    {

     

    if { [HTTP::header "Accept-Language"] starts_with "ar" }

     

    {

     

    HTTP::redirect "http://mydomain/dsb/user-agent/arabic/index.ar"

     

    }

     

    else

     

    {

     

    HTTP::redirect "http://mydomain/dsb/user-agent/english/index.en"

     

    }

     

    }

     

    }

     

    }

     

     

    Will it work?

     

     

    Thanks

     

    Bhuvnesh
  • Irule sometime do not like to many redirects statements I will do something as follow when HTTP_REQUEST {

     

    if {[HTTP::uri] equals "/" } then { if { [HTTP::header "Accept-Language"] contains "en"} then {set Language "english/index.en"} elseif { [HTTP::header "Accept-Language"] contains "ar"} then {set Language "arabic/index.ar"} elseif { [HTTP::header "Accept-Language"] contains "fr"} then {set Language "french/index.fr"} HTTP::redirect "$Language" }

     

    }