Rewriterule Image path

Posted on 2007-08-02
Last Modified: 2010-05-18
Hi experts,
For the purpose of Apache mod_write (ISAPI_Rewrite)

My pages contain some references to  images as

But the images should be served from
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 :-)

Question by:crazyguyindore
    LVL 11

    Expert Comment

    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]

    Author Comment

    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 (and serves images from instead)
    RewriteRule ^/[^/]+/((images)/.*)$ /$1

    But I still need to figure out how to ignore the extra string before after "/images/" and before "__" in should serve

    Any help will be appreciated!

    Thanks :-)

    LVL 16

    Accepted Solution

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

    Author Comment

    Still no luck! any other ideas?

    Thanks for your time.

    should serve

    Author Comment

    It worked actually.

    And thanks for the explanation.


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Prologue It is often required to host multiple websites on a single instance of IIS, mostly in development environments instead of on production servers. I am sure it is not much a preferred solution on production servers but this is at least a pos…
    It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now