Rewrite: fixing Metadot Kluginess

Greetings. I’m implementing portal software called Metadot. It was
orginally Perl – ported to Rails about 1 yr ago. There’s a bunch of
Perl-isms and silliness that makes it somewhat dependent on Apache2 /

I’m trying to use Nginx to proxy/balance dynamic requests to multiple
Apache2/Passenger servers. I want Nginx to serve up all static content
so that Aapche2 can serve just rails. They put attachments and images
in a separate directory outside the rails root. Then they pre-pended
the filename with 8 digits made up of zeros and the file’s id. I want
to rewrite specific file formats to their actual filenames and dirs.

Example for user uploaded images. {png | ico | jpg | gif | etc…}

request comes in as: /metadot/image_library/image.gif

maps to: …/…/metadot-on-rails-attachments/00000001/00000022-image.gif

22 is the file id and image.gif is the [already unique] filename.
metadot-on-rails-attachments is at the same level as the rails root, not
inside it.

Please help! I’ve been lost on this all day.

Thanks! Paul

Ooops. One more thing. As far as I can tell, the 00000001 directory is
a constant. (I know – silly, right?)