Htaccess: if image not exist redirect to coming_soon.jpg

Hi,

I hate writing mod_rewrite rules and I just end up killing my website when I try to hack it :cry:

I have created a jQuery slide image replacment system (based on a UK map, using image maps).

I need the site to show the images if they exist, but if not show coming_soon.jpg.

Here is what I hacked together myself so far (I know it is crap and wrong):

# regional slides
RewriteCond %{REQUEST_URI} ^/design/images/regional/? [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ coming_soon.jpg [L]

Basically, if the browser (javascript) requests h**p://www.example.com/design/images/regional/cumbria.jpg and it exists, show the image. If the image does NOT exist, serve h**p://www.example.com/design/images/regional/coming_soon.jpg instead (but serve it with the filename cumbria.jpg (or whatever was requested).

AND I only want this rule to apply if the are requesting something from h**p://www.example.com/design/images/regional/*

Any help you can provide the tiny, rotting bit of my brain that is dedicated to url rewriting would be hugely appreciated.

Many thanks,

atw

Awww, you’re very close!

Try this:


RewriteCond %{REQUEST_URI} ^/design/images/regional [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .? design/images/regional/coming_soon.jpg [L]

@ScallioXTX: Thank you for the quick reply.

Unfortunately, it doesn’t work.

One point I forgot to mention before is that this is actually running on IIS using ISAPI Rewrite (Helicon Tech - IIS modules and ISAPI filters for URL rewriting and search engine optimization) – I believe that this uses the exact same syntax etc…

Hi,

Don’t worry, I had to change a load of other things for another reason and this has allowed me to change my approach and I am now dealing with this as an if statement in the javascript.

Many thanks for your time.

atw

atw,

Since you actually wanted to redirect IMAGES to coming_soon.jpg, use image extensions in the regex of the RewriteRule. That should solve your problem with mod_rewrite (EVEN in IIS’s implementation).

Regards,

DK