现在部分解决的问题。 一个能够stream利地讲Apache的天才可以照亮这个事情。
GIVEN:大多数代理服务器,不要使用“?”来caching资源 即使在响应中存在Cache-control:public头部,它们的URL也是如此。 要为这些资源启用代理caching,我必须从对静态资源的引用中删除查询string,而不是将参数编码到文件名称中。
目前有
<img src="/imgcpu?src=folder1/photo_citty.jpg&w=3500&h=10&c=p&q=90" /> <img src="/imgcpu?src=folder2/photo_doggy.jpg&w=100&h=200&c=p" /> <img src="/imgcpu?src=folder3/photo_birds.jpg&w=200&h=500&f=bw" /> <img src="/imgcpu?src=folder3/photo_frogs.jpg&w=200&f=bw" />
想
<img src="/IMG-folder1/photo_citty.jpg_w3500_h10_cp_q90" /> <img src="/IMG-folder2/photo_doggy.jpg_w100_h200_cp" /> <img src="/IMG-folder3/photo_birds.jpg_w200_h500_cs_fbw" /> <img src="/IMG-folder3/photo_frogs.jpg_w200_fbw" />
我知道“img?src =”是一个不好的部分,已经处理了:
# Rewrite imgcpu?src= thumbnail maker to nice static urls RewriteRule ^IMG-(.*) /imgcpu?src=$1 [L]
但其余的我坚持。 任何和所有的线索是非常受欢迎的。 谢谢。
进展
IMG-folder1/photo_citty.jpg&w=3500&h=10&c=p&q=90 WORKS
IMG-folder1/photo_citty.jpg_w-3500_h-10_c-p_q-90 DOESNT WORK
IMG-folder1/photo_citty_w-3500_h-10_c-p_q-90.jpg DOESNT WORK
RewriteRule ^IMG-(.+)_w-(.+)_h-(.+)_c-(.+)$ imgcpu\?src=$1&w=$2&h=$3&c=$4 [L] RewriteRule ^IMG-(.+)_w-(.+)_h-(.+)_f-(.+)$ imgcpu\?src=$1&w=$2&h=$3&f=$4 [L] RewriteRule ^IMG-(.+)_w-(.+)_h-(.+)$ imgcpu\?src=$1&w=$2&h=$3 [L] RewriteRule ^IMG-(.+)_w-(.+)$ imgcpu\?src=$1&w=$2 [L] RewriteRule ^IMG-(.+)_h-(.+)$ imgcpu\?src=$1&h=$3 [L] # pfff endless possibilities!!
这甚至不包括首先给出高度的情况。 不,这不行!
让我们find一个解决scheme来redirect所有可选&w =或&h =类似于&[az] =(。*)sothat _h-或_w-是通用的,不pipe什么字母在那里_c-或_q-什么都可以适合。 这将是一个非常受欢迎的重写。
同时这个工程!
<img src"/IMG-folder/photo_w100_h100_cf_q60.jpg"/>
通过使用:
RewriteRule ^IMG-(.+)_w(.+)_h(.+)_c(.+)_q(.+).jpg$ imgcpu\?src=$1\.jpg&w=$2&h=$3&c=$4&q=$5 [L]
所以现在的任务是:
将[photo123.jpg]&[az]=(.*)&[az]=(.*)etcettera任何或所有查询[photo123.jpg]&[az]=(.*)&[az]=(.*)etcettera为photo123_X-x_Y-y(optionally more queries).jpg
规则
RewriteRule ^/imgcpu\?src=(.+)&w=(.+)&h=(.+)&c=(.+)&q=(.+)$ /IMG-$1_w-$2_h-$3_c-$4_q-$5
将处理第一种情况,问题是你需要一个更复杂的RE来处理第二和第三行的差异(缺lessURL的q和p部分,额外svariables等)。
为了防止一个冗长的, 只写正则expression式的混乱,我会为这三种情况分别制定一个不同的规则。
RewriteRule ^IMG-(.+)_w-(.+)_h-(.+)_c-(.+)$ imgcpu\?src=$1&w=$2&h=$3&c=$4 [L] RewriteRule ^IMG-(.+)_w-(.+)_h-(.+)_f-(.+)$ imgcpu\?src=$1&w=$2&h=$3&f=$4 [L] RewriteRule ^IMG-(.+)_w-(.+)_h-(.+)$ imgcpu\?src=$1&w=$2&h=$3 [L] RewriteRule ^IMG-(.+)_w-(.+)$ imgcpu\?src=$1&w=$2 [L] RewriteRule ^IMG-(.+)_h-(.+)$ imgcpu\?src=$1&h=$3 [L] # pfff endless possibilities!!
这甚至不包括首先给出高度的情况。 不,这不行!
让我们find一个解决scheme来redirect所有可选&w =或&h =类似于&[az] =(。*)sothat _h-或_w-是通用的,不pipe什么字母在那里_c-或_q-什么都可以适合。 这将是一个非常受欢迎的重写。
同时这个工程!
<img src"/IMG-folder/photo_w100_h100_cf_q60.jpg"/>
通过使用:
RewriteRule ^IMG-(.+)_w(.+)_h(.+)_c(.+)_q(.+).jpg$ imgcpu\?src=$1\.jpg&w=$2&h=$3&c=$4&q=$5 [L]
所以现在的任务是:
将[photo123.jpg]&[az]=(.*)&[az]=(.*)etcettera任何或所有查询[photo123.jpg]&[az]=(.*)&[az]=(.*)etcettera为photo123_X-x_Y-y(optionally more queries).jpg