Httpd – Apache+mod_jk and a specific 404 handler

apache-2.2errordocumenthttp-status-code-404httpdmod-jk

I have a relatively simple Apache httpd + Tomcat via mod_jk setup that works well, but I need to have Tomcat handle certain 404 conditions. Basically, the httpd service will handle images and PDF files and the occasional IIS hacking attempt. However the PDF files are actually created by Tomcat and deleted from the filesystem later, and some people have placed links to those volatile PDF documents out on the web. This results in 404 messages, when what I really want is to have the user see the form where the PDF was generated from.

I can, of course, have Tomcat handle all 404s:

ErrorDocument 404 /404.jsp

But there are too many of them, and Tomcat just sees 404.jsp, it doesn't know what the original URL was. What I need is:

  1. httpd continues to serve up all images, PDFs, etc.
  2. if a PDF file is missing, send that request through mod_jk. For all other types, it continues to respond with its own 404.
  3. Tomcat figures out where the PDF really came from and forwards the user on to that page.

Is this doable without too much .conf surgery?

Best Answer

You could make smart 404 jsps that use look at the referring url and redirect the request based on some logic in the jsp, or redirect via javascript. If the referrer has .pdf in the url, parse the url and redirect the user to the proper form, assuming you can lookup the form you need based on the pdf requested.