Forum Moderators: phranque

Message Too Old, No Replies

possible to calculate a value with mod rewrite?

         

rizoto

12:58 pm on Jan 14, 2008 (gmt 0)

10+ Year Member



Hello,

There are thousands of thumbnails on my webserver and I'd like do group them by category id in seperate directories and use mod_rewrite to direct the request to the right file in the right directory. for example /thumbs/62_1_picname.jpg should translate to /thumbs/7/1.jpg because category 62 is in a directory named 7 (Let say I want to group every 10 categories together).

Is it possible to do that with mod_rewrite? Basically I need to make some calculations on the category value.

If it's not possible, what's the best approach I should take? I just don't want to dump so many files in one directory because of performance issues and maybe even hosting limitations

Thank you

gergoe

1:20 pm on Jan 14, 2008 (gmt 0)

10+ Year Member



You will need to look into the documentation of RewriteMap Directive [httpd.apache.org], and look for external rewriting in there, that's something for you (a script would determine on the fly which file to go in which directory using an external script). Alternatively, you could generate a filename to category map file too (not on the fly).

And last, why not making these directories, not based on category, but the actual filename? I mean this:

asdsd.jpg -> /a/s/asdsd.jpg 
asj2d.jpg -> /a/s/asj2d.jpg
awewe.jpg -> /a/w/awewe.jpg
reqre.jpg -> /r/e/reqre.jpg

This one is perfectly possible with mod_rewrite without any external file, or any 'complicated' rewriting solutions.

jdMorgan

1:33 pm on Jan 14, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It would be far easier to just use part of the picname as the directory for the thumb-name. For example:

/thumbs/62_1_picname.jpg -> /thumbs/6/2_1.jpg
/thumbs/62_2_picname.jpg -> /thumbs/6/2_2.jpg
...
/thumbs/71_1_picname.jpg -> /thumbs/7/1_1.jpg

Doing that requires only a simple re-arrangement of the URL text, with no calculation needed, and is a 'standard' method used on sites with lots of files that 'appear' to reside in one URL-directory.

Note that what I've shown is just an example -- You can re-arrange the URL in any way you like to form the filepath, dropping parts of the URL-text, adding extra fixed text, etc.

Jim