Regex .htaccess-如果扩展名为.png,则从URL中删除目录

Regex .htaccess-如果扩展名为.png,则从URL中删除目录,regex,apache,.htaccess,mod-rewrite,Regex,Apache,.htaccess,Mod Rewrite,我有一个.png images的目录www.example.com/I/image.png,位于/var/www/html/example.com/I/image.png 然而,我还有一些其他的.png图像www.example.com/css/glyph/image.png,它位于/var/www/html/example.com/css/glyph/image.png中 我希望能够从根目录访问/I/文件夹中的图像。 示例www.Example.com/image.png实际上会带我去www.

我有一个.png images的目录www.example.com/I/image.png,位于/var/www/html/example.com/I/image.png

然而,我还有一些其他的.png图像www.example.com/css/glyph/image.png,它位于/var/www/html/example.com/css/glyph/image.png中

我希望能够从根目录访问/I/文件夹中的图像。 示例www.Example.com/image.png实际上会带我去www.Example.com/i/image.png


是否有任何一种.htaccess解决方案允许我这样做?

对这些问题的回答应该有助于-

具体而言:

RewriteEngine ON
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^.*\.(gif|jpg|png)$ http://imgserv.example.com/forums/$0 [L,R]

您可以在root.htaccess中使用此代码:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^./]+\.png)$ /i/$1 [L,NC]