Forum Discussion
Mike_86382
Altostratus
Apr 23, 2009A twist on the 404 status code
Hello. I am new to iRules, but I have an important task to accomplish:
I need to rewrite an http response status code from 200 to 404 whenever a particular page is sent to the client. We need to do this as we have problems with search engines and 404 page not returning a proper 404.
So, http://www.mydomain.com/404.htm (which normally returns a 200 because of our CMS system) needs to return a 404 status code whenever this page is served.
Can this be done with iRules?
Your help is greatly appreciated.
Thanks,
Mike
- Mike_86382
Altostratus
This is what I have so far: - Mike_86382
Altostratus
My example doesn't work of course. Doh! - Nat_Thirasuttakorn
Employee
you may try HTTP::respond command - hoolio
Cirrostratus
Hi Mike, - tom_llewellyn-s
Nimbostratus
HTTP::respond is what you are looking for, mentioned above. You will also need to include a 404 page, by setting it in a variable possibly at RULE_INIT, if it's static. - Mike_86382
Altostratus
Thanks for the great direction everyone. To solve the immediate need, I will place our 404 html content in the iRule like so: - hoolio
Cirrostratus
Hi Mike, - Mike_86382
Altostratus
Excellent point Aaron. We will have to change the way this works, because it is issueing a 302 before the 404 (defeats the original purpose). I think we will modify the iRule to detect the server response containing status 302 and the uri of the 404 page, and instead respond with a 404 status and the 404 content. - hoolio
Cirrostratus
Something like this should work for this:when HTTP_RESPONSE { Check if response is a redirect and the Location header contains the 404 page if { [HTTP::is_redirect] and [HTTP::header Location] contains "http://www.mydomain.com/404.htm"}{ Send a 404 with custom content HTTP::respond 404 content { Custom 404 All this content comes from our real 404.htm page, but is manually copied into here. } } }
- Mike_86382
Altostratus
This looks good. I'll modify our iRule and do some testing. I think this is really close to what we need.
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects