Devlopers Friend
Devlopers Friend

Reputation: 449

show custom image if image not found

i want to show a custom image if image not found using htacess my images are saved in an folder named "file-logo" and i am trying to use the code below but it is not working i want that all my images should be shown and in case image not found it should send an custom image "unknown.png"

    <filesMatch "\.(jpg|png|gif)$">
    ErrorDocument 404  file-logo/unknown.png
    </filesMatch>0

Upvotes: 2

Views: 231

Answers (2)

Ashish Garg
Ashish Garg

Reputation: 37

Instead of ErrorDocument use mod_rewrite like this from site root .htaccess:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(jpe?g|png|gif)$ file-logo/unknown.png [L,NC]

Upvotes: 2

anubhava
anubhava

Reputation: 785266

Instead of ErrorDocument you can use mod_rewrite like this from site root .htaccess:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(jpe?g|png|gif)$ file-logo/unknown.png [L,NC]

This is assuming http://example.com/file-logo/unknown.png is a valid URL.

Upvotes: 3

Related Questions