Forum Discussion
404 status issue
I'm curious as this is weird behavior I've encountered with this set of code:
when HTTP_RESPONSE {
if { ([HTTP::status] equals "404") } {
if a 404 is return, then do a 301 redirect to our custom 404 page
HTTP::respond 301 Location "http:[HTTP::host]/portal/site/erp/404/"
return
}
}
Problem: If the page returns a 200 but there is a missing image, the redirect will take place. I was under the impression that the whole page has to returned 404 before to set the "HTTP::status" to true. Is that correct or am I missing something?
Any clarification is fully appreciated.
Thanks.
Regards,
TX
3 Replies
- Chris_Miller
Altostratus
A page is merely a collection of objects for which HTTP GET requests must be made. If for instance a page had 12 images, a 404 for any of them could trigger the rule. Also, HTTP::host shouldn't be used in HTTP_RESPONSE since there's no host header. You'll want to set a variable from HTTP_REQUEST and check the variable from HTTP_RESPONSE.
Something like this would work:when HTTP_REQUEST { set hostvar [HTTP::host] } } when HTTP_RESPONSE { if { [HTTP::status] eq "404" } { if a 404 is returned, send a 301 redirect for our custom 404 page HTTP::respond 301 Location "http://$hostvar/portal/site/erp/404/" } }
Let me know if you have any issues with that. - Hello ,
I understand, but what if condition would be used if you're just interested if the page it's self is rendered? Meaning we can ignore the x images that are missing as long as the page is found and renders to the browser.
Please let me know.
Thanks in advance.
Regards,
TX - hoolio
Cirrostratus
TX,
I didn't think the browser would follow a redirect if the 30x response came for an element within the page. Can you use a browser plugin like HttpFox for Firefox or Fidder to see exactly what's triggering the change of the page?
Aaron
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
