S
S
slava kk2019-04-05 12:14:50
Apache HTTP Server
slava kk, 2019-04-05 12:14:50

Replace not found image with another one via htaccess?

How to replace an unfound image in a folder with another one using htaccess?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kirill Proger, 2019-04-05
@slavchickalpha

The easiest option is to place an .htaccess file in the img directory containing such code
or like this

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^img/.*\.(jpg|jpeg|png|gif)$ /img/404.png [L]

it's already in the root of the site.

V
Valentin, 2019-04-05
@romanko_vn

It's easiest like this

$("img").on("error", function(){
        $(this).attr('src', '../img/no-picture.png');
    });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question