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 difference.
The [L] means last.
What you really need to use as well is the [PT] flag to indicate that the resultant path from your rewrite rule should be passed through to next handler which in your case is the alias directive.
As the [PT] tag also implies the [L] tag you no longer require [L] aswell.
That [L] you have after the RewriteRule means "Last"
To be honest, I believed this only meant further RewriteRule lines would be ignored, but it might be worth checking out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With