Forum Discussion
Redirect to a custom error page when server response is matched with any specific code
Hi I need to respond and redirect on custom response from the server ( tomcat/apache )
I have this iRule , just need to verify if the following iRule should work if we wanted to create a respond page and then redirect the traffic to the homepage ?
when HTTP_REQUEST {
set hostvar [HTTP::host]
set urivar [HTTP::uri]
set delay 4
}
when HTTP_RESPONSE {
if { [HTTP::status] eq “404 } {
HTTP::respond 200 content \ “
Unfortunately, your request for $hostvar$urivar casued a 404 error. After 4 seconds, you’ll automatically be redirected to our home page. If you feel you’ve tried a valid link, please contact webmaster@sample.com. Sorry for this inconvenience.
” “Content-Type” “text/html”
}
}Here using HTTP:respond we are holding the user for a delay and then sending the redirect to www.mysite.com.
If you can check the code and verify this works that would be great...
Thanks.
2 Replies
- JG
Cumulonimbus
Syntax does not seem right. See:
https://devcentral.f5.com/wiki/irules.HTTP__respond.ashx
- hoolio
Cirrostratus
Can you try this?
Also, you should consider HTML encoding the host and URI values in the iRule to protect site users from XSS.
You can do this using string map:
https://devcentral.f5.com/wiki/iRules.HTML_encoding_proc.ashxwhen HTTP_REQUEST { set hostvar [HTTP::host] set urivar [HTTP::uri] set delay 4 } when HTTP_RESPONSE { if { [HTTP::status] == 404 } { HTTP::respond 200 content " Unfortunately, your request for ${hostvar}${urivar} casued a 404 error. After 4 seconds, you’ll automatically be redirected to our home page. If you feel you’ve tried a valid link, please contact webmaster@sample.com. Sorry for this inconvenience. " "Content-Type" "text/html" } }
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com