Forum Moderators: phranque
In my .htaccess file, what is most efficient way of handling images which may or may not exist?
Should I just use:
ErrorDocument 404 /thumbs/blank.jpg
or would something like this be better:
RewriteCond %{REQUEST_FILENAME}!-f
RewriteRule .* /thumbs/blank.jpg
Which would put the least strain on my apache server if the image directory has 10,000 + files in it, and 50% of the requests will be for images that don't exist?
Thank you,
Dave
Since calls to the file system are expensive in terms of CPU utilization, and since the server already checks for file exists, I'd avoid adding an additional check, especially since your images directory is likely to be the target of the majority of requests to your server (assuming that each page loads several images).
With that in mind, be sure you're setting proper expires and cache-control headers on that images directory as well -- see mod_expires and mod_headers.
Jim