Rewriting a CGI url to a PNG

The website kanji.sljfaq.org/kanjivg/ creates a PNG graphic from vector graphics information. A previous version created a file on the server's disk and then sent the user its URL. Since the page was fairly popular, this filled up the disk with lots of images. I also wanted to expand the service so that users could view the graphics with different sizes, or thicknesses of lines. This would result in even more files.

One solution would have been a cron job to delete old files. However, that way nobody can link to the files. I decided to make a cgi program which creates the graphics and sends them to the user without ever storing them on disk. This way it is easy to link to images. To make the URLs of the image files redirect to the CGI script, I used the following lines in .htaccess:

RewriteEngine On
RewriteRule ^kanjivg/img/kanji([0-9a-fA-F]{4})\.png$ /kanjivg/memory.cgi?c=$1

Copyright © Ben Bullock 2009-2018. All rights reserved. For comments, questions, and corrections, please email Ben Bullock (benkasminbullock@gmail.com) or use the discussion group at Google Groups. / Privacy / Disclaimer