Forum Discussion

krisnaseechurn's avatar
krisnaseechurn
Icon for Altostratus rankAltostratus
Jun 10, 2022

**** HELP WITH IRULE FOR REDIRECTION*******

I have a requirement to diable redirects from API and Async calls within this part of my irule:

if { [HTTP::status] == "404" } {
set irule "Irule_Catch_404"
set http_status [HTTP::status]
set res_start_time [clock format [clock seconds] -format "%Y/%m/%d %H:%M:%S"]
set req_elapsed_time [expr {[clock clicks -milliseconds] - $tcp_start_time}]
if { [HTTP::header exists "Content-Length"] } {
set req_length [HTTP::header "Content-Length"]
} else {
set req_length 0
}
HSL::send $hsl "<190>,f5_irule=Splunk-iRule-HTTP,env=$env,src_ip=$client_address,vip=$vip,irule=$irule,http_method=$http_method,http_host=$http_host,http_port=$http_port,http_dest=$dest_url,http_uri=$http_uri,http_url=$http_url,http_version=$http_version,http_user_agent=\"$http_user_agent\",http_content_type=$http_content_type,http_referrer=\"$http_referrer\",req_start_time=$req_start_time,virtual_server=\"$virtual_server\",bytes_in=$req_length,res_start_time=$res_start_time,node=$node,node_port=$node_port,http_status=$http_status,req_elapsed_time=$req_elapsed_time,bytes_out=$res_length\r\n"
HTTP::redirect $pagenotfoundurl
set uri_rewritten 1
return
}

Can someone suggest an appropriate way to do this please? This is what I thought but I may be wrong!

 

[HTTP::status] starts_with "5" && {!{[HTTP::header] contains "Content-Type:application/json" || ![HTTP::header] contains "Content-Type:application/xml"}

  • if you still can please change your title and remove the asterisks, it really isn't needed here.

    did you try it like this? usually the best way to figure out if it works.

    first thing that triggers me is status starts_with 5, in principle redirects are usually 3xx. then add a line to log to check if the if statement gets hit.

    post another version of the irule with the event(s) there also.