I have a directory outside the webroot that is used for storing images uploaded from a separate admin system. Images are stored in this format:
filepath/writable/images/00/00/23/65/filename-236581.jpg
(where the webroot is filepath/html)
...for example. Here, 236 is the ID of the image in the database, and the file system is broken into numbered directories to stop more than 100 inodes from being used within one directory.
I want to be able to access these from the front-end webserver, like this: http://(server)/filename-236581.jpg Where filename is an seo-optimised string, the same as on the name of the actual file.
I can get mod-rewrite to rewrite the URL so that it contains the extra numbered directories, and I can get alias to redirect the request to the writable/images directory, but I can't do both at the same time. If I put both the alias and mod_rewrite directives in, it ignores the alias one and the error log complains that it can't find filepath/html/uploaded-images.
Here is what I have so far:
RewriteRule ^(.)\/([^\/])-([0-9]).(gif|jpg|jpeg|png)$ /uploaded-images/00/00/00/00/$2-$3.$4 [L,NC] ...and so on, all the way up to: RewriteRule ^(.)\/([^\/])-([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]).(gif|jpg|jpeg|png)$ /uploaded-images/$3$4/$5$6/$7$8/$9$10/$2-$3$4$5$6$7$8$9$10$11$12.$13 [L,NC]
alias /uploaded-images "filepath/writable/images"
Removing the [L] makes no dirrerence.