开发者

mod_rewrite to find missing /img/foo.jpg in /img/f/

开发者 https://www.devze.com 2022-12-23 09:57 出处:网络
I\'ve got a folder of images which is reaching a critical mass after a few years. I want to move images into alphabetical folders, so that /img/foo.jpg goes into /img/f/foo.jpg and /img/bar.jpg goes

I've got a folder of images which is reaching a critical mass after a few years.

I want to move images into alphabetical folders, so that /img/foo.jpg goes into /img/f/foo.jpg and /img/bar.jpg goes into /img/b/bar.jpg and so on.

In order to make the transition smooth, and to allow the manual uploaders to put stuff into the top level, I'd like to use mod_rewrite to do this:

  • if /img/foo.jpg exists, serve it up,
  • if not look for it in /img/f/foo.jpg

thanks fo开发者_如何学Cr any suggestions.

For the record, no, I don't think we need to go /img/f/fo/foo.jpg just yet.


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号