0

a question that is now partially resolved. A genius who can speak Apache fluently can shine light into this matter...

GIVEN: Most proxies, do not cache resources with a "?" in their URL even if a Cache-control: public header is present in the response. To enable proxy caching for these resources, i have to remove query strings from references to static resources, and instead encode the parameters into the file names themselves.*

CURRENTLY HAVE

 <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" />

WOULD LIKE

 <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" />
  • The images will reside in 1 folder deep on the root (never deeper)
  • the img.php?src= or img?src= will be consistently named this forever

I know the "img?src=" is a bad part and have already handled with that:

# Rewrite imgcpu?src= thumbnail maker to nice static urls
RewriteRule ^IMG-(.*) /imgcpu?src=$1 [L]

But the rest im stuck at. any and all clues are greatly welcome. Thanks.

PROGRESS
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!!

And this doesnt even cover the cases where first the height is given the width. No this shall not work!

Lets find a solution to redirect all OPTIONAL &w= or &h= with something like &[a-z]=(.*) sothat _h- or _w- are universal and doesnt matter what letter is there _c- or _q- anything could then fit. THAT would be a very welcome rewrite.

Meanwhile this does works!!

<img src"/IMG-folder/photo_w100_h100_cf_q60.jpg"/>

by using:

RewriteRule ^IMG-(.+)_w(.+)_h(.+)_c(.+)_q(.+).jpg$ 
            imgcpu\?src=$1\.jpg&w=$2&h=$3&c=$4&q=$5 [L]

So the assignment Now is:
Rewrite any or all of the queries that follow [photo123.jpg]&[a-z]=(.*)&[a-z]=(.*)etcettera into photo123_X-x_Y-y(optionally more queries).jpg

Sam
  • 423
  • 3
  • 7
  • 23

2 Answers2

1

The rule

RewriteRule ^/imgcpu\?src=(.+)&w=(.+)&h=(.+)&c=(.+)&q=(.+)$ /IMG-$1_w-$2_h-$3_c-$4_q-$5

Will deal with the first case, the problem is that you would need a much more complex RE to deal with the differences on the second and third line (missing q and p parts of the url, extra s variable, etc).

To prevent the mess of a long and write-only regular expression I would make one different rule for each of the three cases.

coredump
  • 12,713
  • 2
  • 36
  • 56
  • Thanks very much CoreCemp, but as you say we havent found an elegant solution yet... You did however inpired me to partially solved it: – Sam Dec 04 '10 at 22:21
  • CoreCemp is a new way to see my nickname :P – coredump Dec 05 '10 at 07:32
  • :D now updating the question. im bilingually dyslectic sorry i meant CoreDump :D – Sam Dec 06 '10 at 01:51
  • Daer CoreDump, ive moved the second part, which is a much more difficult sub-question, to another question,after awardign you the answer for this part. http://serverfault.com/questions/209437/is-there-an-elegant-solution-to-rewrite-long-imagequery-urls-into-cachable-nice – Sam Dec 06 '10 at 02:23
0
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!!

And this doesnt even cover the cases where first the height is given the width. No this shall not work!

Lets find a solution to redirect all OPTIONAL &w= or &h= with something like &[a-z]=(.*) sothat _h- or _w- are universal and doesnt matter what letter is there _c- or _q- anything could then fit. THAT would be a very welcome rewrite.

Meanwhile this does works!!

<img src"/IMG-folder/photo_w100_h100_cf_q60.jpg"/>

by using:

RewriteRule ^IMG-(.+)_w(.+)_h(.+)_c(.+)_q(.+).jpg$ 
            imgcpu\?src=$1\.jpg&w=$2&h=$3&c=$4&q=$5 [L]

So the assignment Now is:
Rewrite any or all of the queries that follow [photo123.jpg]&[a-z]=(.*)&[a-z]=(.*)etcettera into photo123_X-x_Y-y(optionally more queries).jpg

Sam
  • 423
  • 3
  • 7
  • 23