只用.htaccess重写图像

我试图做以下types的映射从URL到文件系统的图像文件只

mysite.com/image.jpg -> images/image.jpg mysite.com/folder/other.jpg -> images/folder/other.jpg mysite.com/x/y/z.jpg -> images/x/y/z.jpg 

我试过以下,但它显然会导致无限的redirect循环:

 RewriteRule ^(.*\.(gif|jpg|png))$ images/$1 [QSA,L] 

任何mod_rewrite大师在这里?

只要在你的规则之前添加一个条件,看看它是否已经被重写为图像/

 RewriteCond %{REQUEST_URI} !/images/.* RewriteRule ^(.*\.(gif|jpg|png))$ images/$1 [QSA,L]