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
- hoolio
Cirrostratus
Hi, - 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'. - 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.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" } }
- 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.... - 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.
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