问题
Here's what I am trying to do, for example . . .
http://www.website.com/images/folder-with-a-crazy-name/any-image-at-all.jpg
would rewrite to . . .
http://www.website.com/images/folder-with-a-crazy-name.jpg
Does this make sense?
Any help would be appreciated.
回答1:
To rewrite all jpeg image files in a folder to that folder with .jpg
appended
RewriteRule ^images/(.+?)/[^/]+?\.jpg$ /images/$1.jpg [L]
回答2:
Just paste this into your .htaccess file:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^images/([a-z0-9-_]+)/any-image-at-all.jpg /images/$1.jpg
Or if you want even the other image formats to be rewritten, then just replace the third and the last line on the code above with this rule:
RewriteRule ^images/([a-z0-9-_]+)/any-image-at-all.([a-z0-9]{3}|[a-z0-9]{4}) /images/$1.$2
If the the folder images is also a variable, then try one of the following rules below:
RewriteRule ^([a-z0-9-_]+)/([a-z0-9-_]+)/any-image-at-all.jpg /$1/$2.jpg
If the file extension is a variable, then try this:
RewriteRule ^([a-z0-9-_]+)/([a-z0-9-_]+)/any-image-at-all.([a-z0-9]{3}|[a-z0-9]{4}) /$1/$2.$3
来源:https://stackoverflow.com/questions/15839426/htaccess-rewrite-all-image-requests-from-a-non-existent-folder-to-folder-name-jp