Rewriterule Image path

Hi experts,
For the purpose of Apache mod_write (ISAPI_Rewrite)

My pages contain some references to  images as
http://www.site.com/images/WhatEverString1__mail.jpg
http://www.site.com/images/WhatEverString2__print.jpg 
etc.

But the images should be served from
http://www.site.com/images/mail.jpg
http://www.site.com/images/print.jpg
and so on...

In other words we should ignore the characters between "images/" and "__imgname.[gif|png|jpg]"

Could someone please give me EXACT Rewriterule (and ReWritecond) for the above please.
A brief explanation will be appreciated.

Thanks a lot in advance :-)

crazyguyindoreAsked:
Who is Participating?
 
HackneyCabConnect With a Mentor Commented:
How about:

RewriteCond %{REQUEST_URI} \.(gif|png|jpg)$
RewriteRule ^images/[^_]+_{2}(.*)$ /images/$1

This checks that the file requested ends with .gif or .png or .jpg and, if so, tells Apache to look in the images folder for the string that occurs after /images/blahblah__ (I've used a quantifier of 2 underscores, but change that number if the number of underscores is different, or a range).
0
 
JamesCsslCommented:
I don't know how different ISAPI_Rewrite is from mod_rewrite, but this is how it would be done with mod_rewrite:

RewriteRule ^/?images/.*__(.*\.(gif|png|jpg))$ /images/$1 [L]
0
 
crazyguyindoreAuthor Commented:
Hi, sorry that does not seem to work as desired. ISAPI_Rewrite and mod_rewrite use same syntax.

I found another rewriterule which ignores the "/SomeFolder/" between site.com/SomeFolder/images/print.gif (and serves images from site.com/images/print.gif instead)
RewriteRule ^/[^/]+/((images)/.*)$ /$1

But I still need to figure out how to ignore the extra string before after "/images/" and before "__" in
site.com/images/SomeString__print.gif should serve site.com/images/print.gif.

Any help will be appreciated!

Thanks :-)

0
 
crazyguyindoreAuthor Commented:
Still no luck! any other ideas?

Thanks for your time.

PS:
e.g.
site.com/images/dddfgfgdd_print.gif
should serve
site.com/images/print.gif
0
 
crazyguyindoreAuthor Commented:
It worked actually.

And thanks for the explanation.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.