Redirect - Custom 404

From Tech-Wiki
Jump to: navigation, search

Back to iRules

when HTTP_RESPONSE {
    if { [HTTP::status] == "403" } {
        HTTP::respond 404 content "404 File Not Found" Mime-Type "text/html"
    }
    elseif { [HTTP::status] == "404" } {
        HTTP::redirect "http://www.customerrorpage.com"
    }
}

Or below

when HTTP_REQUEST {
  set host [HTTP::host]
  set path [HTTP::path]
}
when HTTP_RESPONSE {
  if { [HTTP::status] eq "404" } { HTTP::redirect "https://${host}/my404page?url=${path}" }
}

You CAN'T use host/uri under RESPONSE, like below:

when HTTP_REQUEST {
 #Redirects all to HTTPS keeps URI intact
 HTTP::redirect https://[HTTP::host][HTTP::uri]
}