I have got a folder of images that is reaching a vital mass following a couple of years.

I wish to move images into alphabetical folders, to ensure that /img/foo.jpg adopts /img/f/foo.jpg and /img/bar.jpg adopts /img/b/bar.jpg and so forth.

To be able to result in the transition smooth, and also to permit the manual uploaders to place stuff in to the top level, Let me use mod_rewrite to get this done:

  • if /img/foo.jpg is available, serve it up,
  • otherwise search for it in /img/f/foo.jpg

thank you for any suggestions.

For that record, no, I do not think we have to go /img/f/fo/foo.jpg at this time.

RewriteCond %{REQUEST_URI} ^/img/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?img/(.)(.*)$ /img/$1/$1$2