Redirect - Custom 404

From Tech-Wiki
Revision as of 18:52, 20 May 2019 by Fabricio.Lima (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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]
}