Forum Moderators: phranque

Message Too Old, No Replies

rewrite of missing images

         

powerflash

2:12 pm on Dec 4, 2010 (gmt 0)

10+ Year Member



Hi all,

Some pages use this url /software/files/2010/12/saperlo_come-fare-una-ricarica-online-dal-portale-wind.jpg but are missing and I must show this default img /bt/nophoto.jpg

I try this

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(software|hardware|apple|software)/files/.*\.jpg$ /bt/nophoto.jpg [L]

but it dont check if header response with 404 error, it response all images also the exist images

jdMorgan

2:21 am on Dec 7, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your code is correct and should work, IF:
1) These images are physically-existing files on the disk, and
2) You delete your browser cache between every 'test case' that you try on your server while testing the code.

If the image URLs are rewritten and/or get handled by a script, then "RewriteCond %{REQUEST_FILENAME} !-f" won't work correctly, because REQUEST_FILENAME refers to physical filepaths, not to URLs.

Another way to accomplish this (although it also depends on physical files) is something like

ErrorDocument 404 /404.html
<FilesMatch "\.jpg$">
ErrorDocument 404 /bt/nophoto.jpg
</FilesMatch>

Here, we declare the default custom 404 error document, but then override it if the requested resource is a .jpg file.

Jim