1

How to create a proper Wordpress(php) 404 fallback for not found images. The JS approach is not suitable because SEO Auditors parse only html, and there are still 404 errors https://prnt.sc/vha4og .

So please do not suggest codes like these - it doesn't resolve the issue : <img src="<?php echo esc_url( $catalog_thumb_image['url'] ); ?>" onerror="this.src='https://site.md/wp-content/uploads/2018/07/logo.png'" alt="<?php esc_attr( the_title() ); ?>">

Or via jquery

$('img').on('error', function() {
    $(this).attr('src', 'https://site.md/wp-content/uploads/2018/07/logo.png');
});
Ion T
  • 119
  • 1
  • 9

1 Answers1

1

Ok - here is the answer :

Our hosting uses a mix of nginx/apache and i thought i must use nginx rules (wrong) .

.htaccess works but i was putting the code at bottom instead of the top of .htaccess .

RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule \.(gif|jpe?g|png|bmp) /logo.png [NC,L] 
# BEGIN
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
# END
Ion T
  • 119
  • 1
  • 9