• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1473
  • Last Modified:

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 :-)

0
crazyguyindore
Asked:
crazyguyindore
  • 3
1 Solution
 
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
 
HackneyCabCommented:
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
 
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now