Redirecting missing images to index.php instead of page **404**

CS-Cart v4.16.1
Support tried to fix my site’s ‘slowness’ but it needs something from my end.
Any clues would be appreciated.
Support’s response:
“I have examined this issue in your store, and the slowdown was caused by the generating of thumbnails for images (as your store has a lot of heavy images).
To improve thumbnails generation performance, I enabled the lazy_thumbnails tweak in the config.local.php file by replacing the following line:
‘lazy_thumbnails’ => false, // generate image thumbnails on the fly
with:
‘lazy_thumbnails’ => true, // generate image thumbnails on the fly
This tweak makes the platform generate thumbnails only when they are requested, instead of all of them at once.
The pages started to load much faster with the enabled tweak, but the thumbnails weren’t displayed on the storefront (please see the attached screenshots). It is caused by an incorrect configuration of your server, which returns a 404 webpage for missing images instead of redirecting to index.php . This behaviour prevents the creation of thumbnails of images used on product pages. So I have disabled the lazy_thumbnails extension.
If you want to use this tweak in your store, you need to contact the server administrators and ask them to fix the problem with redirecting missing images to page 404 instead index.php .”

Approached the host but they referred me back to the developer.
Ultimately I don’t want to spend a lot speeding up a site that was just fine ( with the same number
of heavy images ) in previous versions.

This is not some obscure code by an alien race. It’s non-function should be easily diagnosed by
those in the know rather than become a ping pong game between host and developer.

1 Like

Hi there!

I saw the tickets on this matter in our Help Desk and also even examined them a bit :slight_smile:

The reason, why lazy_load was not working for you, is that the requests similar to this one (I’ve masked your domain):
https://www.somedomain.com/images/thumbnails/300/300/detailed/23/s-l1600_eac01c36-a778-43d1-8fd1-257d718fc9a31.jpg
were returning your server’s 404 page:

Summary

Instead of being processed by the installation itself.

In case of Apache web server, the necessary rule is defined in the .htaccess file:

<IfModule mod_rewrite.c>
RewriteEngine on
...
RewriteCond %{REQUEST_URI} \.(png|gif|ico|swf|jpe?g|js|css|ttf|svg|eot|woff|yml|xml)$ [NC,or]
RewriteCond %{REQUEST_URI} store_closed.html$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*?)\/(.*)$ $2 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L,QSA]

In case of nginx we have the ready configuration that can be used. It also contains necessary rules:

    location ~* /(\w+/)?(\w+/)?(.+\.(jpe?g|jpg|ico|gif|png|css|js|pdf|txt|tar|woff|svg|ttf|eot|csv|zip|xml|yml))$ {
        access_log off;
        try_files $uri $uri/ /$2$3 /$3 /index.php?$args;
        expires max;
        add_header Access-Control-Allow-Origin *;
        add_header Cache-Control public;
    }

In case of the Litespeed used at your server, unfortunately we don’t have ready configuration, so you need to contact your server administrators / hosting support in order to make the necessary changes to the server configuration.

I hope it will help you.

1 Like