将图像URL重写为一个脚本,该脚本将调整所请求图像的大小


Rewrite image URL to a script which resizes the requested image

使用Apache的mod_rewrite,我如何重写以下URL

http://us.louisvuitton.com/images/is/image/lv/1/VE_DI1_L/louis-vuitton-fall-2015-campaign--Series3_DI1.jpg?wid=1360&hei=633

,以便它指向另一个页面,如以下URL

http://us.louisvuitton.com/image.php?file=images/is/image/lv/1/VE_DI1_L/louis-vuitton-fall-2015-campaign--Series3_DI1.jpg&wid=1360&hei=633

哪个应该输出自定义大小的图像?

,

关于可能的副本:

它看起来像

server.com/thumb.php?file=images/1.jpg&wid=120

我想要的应该是

server.com/images/1.jpg?wid=120

这应该在Root/下工作。Htaccess文件:

RewriteEngine on
RewriteCond %{THE_REQUEST} /images/is/image/lv/1/VE_DI1_L/([^?]+)'?wid=([^&]+)&hei=([^&'s]+) [NC]
RewriteRule ^ /image.php?file=images/is/image/lv/1/VE_DI1_L/%1&wid=%2&hei=%3 [NE,NC,R,L]

安装phpThumb并将。haccess更改为:

RewriteBase /
RewriteEngine on
RewriteCond %{THE_REQUEST} /images/([^?]+)'?w=([^&]+)&h([^&'s]+) [NC]
RewriteRule ^ /phpThumb.php?src=images2/%1&w=%2&h%3 [NC,L]
Options All

这是一个没有大配置开销的小解决方案,它使用PHP脚本来调整图像大小,并使用Apache重写规则来缓存文件系统中产生的低分辨率图像:https://gist.github.com/davejamesmiller/3236415