Search code examples
prestashopprestashop-1.6

PrestaShop images not showing when friendly-URL is switched on


After an installing a new SSL certificate and changing the PHP version from 5.x to 7.1.28 product images are not shown in the frontend anymore, Chrome dev tools show a 404 error for the image files. They are visible in the backend under product catalog.

It looks like if the image directory is missing, i.e. something like /home-default/ because in the HTML code the image file is supposed to be directly on the document root directory, which obviously is wrong.

When I switch off "Friendly URL" the images are shown. What I tried so far:

  1. Deleted .htaccess, switched Friendly URL to on to regenerate the .htaccess
  2. Emptied cache and regenerated the image thumbnails
  3. Switched back to PHP 5.4
  4. Added AllowOverride All to the vhost config

Nothing helps. On the server is another PrestaShop installation, running same PrestaShop version 1.6.18 also under PHP 7.1.28, there the "Friendly URL" works fine.

I must say I have no clue where to look after this problem.


Solution

  • After spending some time with @Harry, debugging his configuration, we found the solution and I'm sure this will help many others.

    @Harry was using a combo with Nginx + Apache.

    1. We checked his PrestaShop .htaccess file and made sure RewriteEngine was on and triggered properly (e.g. the pages were properly rewrited, only the images were not) - everything was OK.
    2. We tried to write ourselves a basic RewriteRule to redirect a .jpg and it did not work, showing an Nginx 404 page.
    3. We came to the conclusion Nginx was handling all the static content (JS, CSS, JPEG, etc.) and not forwarding it to Apache.

    Solution

    We removed this part from the Nginx configuration:

    location ~ ^/(.*\.(ac3|avi|bmp|bz2|cue|dat|doc|docx|dts|eot|exe|flv|gz|htm|html|img|iso|jpeg|mkv|mp3|mp4|mpeg|mpg|ogg|ppt|pptx|qt|rar|rm|swf|tar|tgz|ttf|txt|wav|xls|xlsx|zip))$ {
                    try_files $uri @fallback;
    }
    

    As a general advice, I would suggest not using Apache+Nginx, PrestaShop works very well with Nginx+PHP-FPM already and you will get great performances.

    If you choose this solution, don't forget to set your PrestaShop rewrite rules directly in Nginx (Example).