Options

Redirect HTTP based on client browser

Posted by patricko0317

I have a need for an Aflex script. I need it to redirect the browser to a different page based on the browser the client is using. If it is IE 9, I need it redirected. Will the following script accomplish this? Also, can I add this to the script you gave me for logging?

when HTTP_REQUEST {
if { [HTTP::header "User-Agent"] contains "MSIE 9" } {
HTTP::redirect "redirectionpage.com"
}
}

Comments

  • Options
    JackofallTradesJackofallTrades Member
    edited February 2014
    Posted by JackofallTrades

    Below will do the trick.

    You also want to order the User-Agent headers with Mozzila being the last. Most User-Agents will have Mozilla in it.

    if { [HTTP::header "User-Agent"] contains "MSIE 9" } {
    HTTP::redirect "redirectionpage.com"
    } elseif {[HTTP::header "User-Agent"] contains "Mozzila" } {
    HTTP::redirect "redirectionpage2.com"
    }

    log local0. "The User-Agent is: [HTTP::header "User-Agent"]"
    }

    Hope this helps.
  • Options
    edited July 2022
    Posted by ddesmidt

    Patrick,
    First yes, you're aFleX is just good 

    Now about incorporating this one in the centralized web server logging aFleX: www.a10support.com/adc/index.php/forum/7...server-log-on-ax#32, that's also possible.


    There are 2 ways of doing it.
    . If you're using 2.6, you can attach multiple aFleX rules to 1 VIP:port => create 2 aFleX and associate both aFleX to the VIP:Port.

    . If you are using 2.4.3, you have to combine these 2 aFleX in 1 aFleX. For that, simply add the "IF IE9" at the beginning of your centralized aFleX.
    Code:





    when HTTP_REQUEST { if { [HTTP::header "User-Agent"] contains "MSIE 9" } { HTTP::redirect "redirectionpage.com" } # Set strings for the "client side" set time_client_request [clock seconds] set clicks_client_request [clock clicks -milliseconds] ...





    Now keep in mind doing though you won't get any log for these requests (since the log action is done in the "HTTP_Response event" and there is no server response (AX does the response).
    If you want the log for these too, here is what I suggest (full aFleX below):
    Code:





    when HTTP_REQUEST { # Set strings for the "client side" set time_client_request [clock seconds] set clicks_client_request [clock clicks -milliseconds] set date_time_request [clock format $time_client_request -format {%Y-%m-%d %H:%M:%S} ] set c_ip [IP::client_addr] set cs_uri_stem [HTTP::host][HTTP::uri] set cs_method [HTTP::method] set s_ip [IP::local_addr] set s_port [TCP::local_port] set host [HTTP::host] if {[HTTP::query] equals ""} { set cs_uri_query [HTTP::query] } else { set cs_uri_query "-" } if {[HTTP::header exists Content-Length]} { set cs_bytes [HTTP::header Content-Length] } else { set cs_bytes "-" } if {[HTTP::header exists Referer]} { set cs_Referer [HTTP::header "Referer"] } else { set cs_Referer "-" } set cs_UserAgent [string map {" " "+"} [HTTP::header "User-Agent"]] if { [HTTP::header "User-Agent"] contains "MSIE 9" } { HTTP::redirect "redirectionpage.com" set log_str "$date_time_request $c_ip $s_ip $s_port $cs_method $cs_uri_stem $cs_uri_query $sc_status $sc_bytes $cs_bytes $final_time_taken $cs_UserAgent $cs_Referer" # write to syslog with Debug level log local0.7 $log_str # write to AX log (turn this for troubleshooting only, as you may have a lot of requests / second) # log $log_str } } when HTTP_RESPONSE { # Set strings for the "server side" set clicks_server_response [clock clicks -milliseconds] set sc_status [HTTP::status] if {[HTTP::header exists Content-Length]} { set sc_bytes [HTTP::header Content-Length] } else { set sc_bytes "-" } # Correct TCL Bug with floating point values set time_taken [expr $clicks_server_response - $clicks_client_request ] if {$time_taken < 10} { set final_time_taken [string range "0.00$time_taken" 0 4] } elseif { $time_taken < 100 } { set final_time_taken [string range "0.0$time_taken" 0 4] } elseif { $time_taken < 1000} { set final_time_taken [string range "0.$time_taken" 0 4] } else { set final_time_taken "[string index $time_taken 0].[string range $time_taken 1 3 ]" } # Format strings for logging set log_str "$date_time_request $c_ip $s_ip $s_port $cs_method $cs_uri_stem $cs_uri_query $sc_status $sc_bytes $cs_bytes $final_time_taken $cs_UserAgent $cs_Referer" # write to syslog with Debug level log local0.7 $log_str # write to AX log (turn this for troubleshooting only, as you may have a lot of requests / second) # log $log_str }
  • Options
    edited February 2014
    Posted by ivanm@a10networks.com

    Hi,

    I´m using this one:

    when HTTP_REQUEST {

    if { ( (not ([HTTP::header User-Agent] contains "iPad") and ([HTTP::header User-Agent] contains "Mobile") or ([HTTP::header User-Agent] contains "Profile")) and ([HTTP::host] equals "mtv.uol.com.br") and ( ([HTTP::uri] equals "/celular") or ([HTTP::uri] equals "/")) ) or ( ([HTTP::cookie exists "device"]) and ([HTTP::host] equals "mtv.uol.com.br") )} {
    HTTP::redirect "m.mtv.com.br"
    }


    }
Sign In or Register to comment.