Forum Discussion
Mike_Rausch_628
Nimbostratus
Dec 20, 2007IRULE to redirect an HTTP Request to a certain file
We have an application that allows you to view a pdf for the object you are currently looking at. The pdf's are all numbered and coincide with the different objects in the application. If you click on the view pdf button for an object that does not have a pdf you get a 404 error message. I am trying to create an IRULE that will redirect you to a file/pdf that states there is no pdf for this object. Trying to do this so we do not have to hack the code for the application. Does any one have any ideas for doing this???
Thanks
Mike
6 Replies
- hoolio
Cirrostratus
Hi,
So if a request is for a PDF and the response from the app is a 404, you want to intercept the response and have the BIG-IP send back a canned PDF that says the PDF they requested isn't there? That might be doable a few ways. How big in bytes is the canned PDF?
Else, if I'm off the mark, can you clarify what you want to happen?
Aaron - Mike_Rausch_628
Nimbostratus
That is exactly what I want to do. The pdf I want to send is only 21 kb. - hoolio
Cirrostratus
Good. One more question: what version are you running? You can get the version from the GUI under System >> General >> Version, or via the CLI using 'b version | head'.
Aaron - hoolio
Cirrostratus
Assuming you're on 9.2.5 or higher, you have the fix for CR64809 which allows sending binary data from an iRule using HTTP::respond.
Take a look at this post for details on how to create a datagroup which contains the base64 encoded binary data of the PDF file (Click here). Name the datagroup pdf_404_file. As noted in that post, the content of the PDF file is loaded in memory, so don't use a large source file or you'll impact the memory TMM has available to function.
Once you have the datagroup defined, you can use a rule like this to send a default PDF to the client if they request a PDF and get a 404 from the application:Create a datagroup containing the base64 encoded binary data from a PDF: http://devcentral.f5.com/Default.aspx?tabid=53&forumid=5&tpage=1&view=topic&postid=9523 when RULE_INIT { Log debug messages to /var/log/ltm? 1=yes, 0=no set ::pdf_404_debug 1 } when HTTP_REQUEST { Don't check response status by default set check_response_status 0 if {[string tolower [HTTP::path]] ends_with ".pdf"}{ Request was for a PDF, so check response status set check_response_status 1 Log debug if {$::pdf_404_debug}{log local0. "Received request for a pdf: [IP::client_addr] -> [HTTP::host][HTTP::uri]"} } } when HTTP_RESPONSE { Check if response was a 404 and request was for a PDF if {[HTTP::status] == 404 and $check_response_status}{ Log a debug message if {$::pdf_404_debug}{log local0. "404 response received. Sending default PDF for [IP::client_addr]"} Respond with the default PDF binary data HTTP::respond 200 content [b64decode [lindex $::pdf_404_file 0]] "Content-Type" "application/pdf" } }
Aaron - Mike_Rausch_628
Nimbostratus
Thanks for the example but I would like to make it less complex unless you think it should be done this way....
I created a rule that checks for a status of 404 and if it finds it you get redirected to a file using HTTP::Redirect.
I would like to be able to check the request first to see if it is a pdf request then check for the 404 error and if all of this is true
then do the HTTP::redirect.
Any suggestions?? - hoolio
Cirrostratus
I thought you wanted to avoid hosting the "404 PDF" on a server. In terms of the BIG-IP it's more efficient to send a redirect to the client than store the PDF content in memory. If you're able to host it another server, just change the HTTP::respond line in the rule above to an HTTP::redirect.
old
HTTP::respond 200 content [b64decode [lindex $::pdf_404_file 0]] "Content-Type" "application/pdf"
new
HTTP::redirect http://www.example.com/path/to/404.pdf
Aaron
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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
