Jump to content

Problem with attachment file in multilanguage


Developer201343

Recommended Posts

Hello everyone, I have a problem with how annoying with prestashop 1.7.6.2
I have a site with 3 languages, Italian English and Spanish. I am inserting pdf attachments into the product screen.
The download doesn't work.
If I disable the languages then it works again because the language code is not present in the url. If I disable the fryend url it works, if I enable it it doesn't work.

Link: /it/index.php?controller=attachment&id_attachment=14 -> Not done
Link: /index.php?controller=attachment&id_attachment=14 -> It works

I have tried 1000 different operations with nginx but I have not been able to find a solution on the internet or anywhere else.
Some idea?

General informations:
Prestashop 1.7.6.2
Nginx server

Nginx configuration:
 

server
{
    # [REQUIRED EDIT] Your domain name goes here
    server_name site.it www.site.it;

    error_log /var/log/nginx/www.site.it-error.log;
    access_log /var/log/nginx/www.site.it-access.log;

    # [REQUIRED EDIT] Absolute path to your website root on the filesystem
    root /www/www.site.it;

    index index.php index.html;

    # to control the amount that can be uploaded.
    client_max_body_size 50M;

    # set admin folder name
    set $admin_dir /admin245tm20au; #Example: admin245tm20au

    location ~ /admin.*/(sell|api|common|_wdt|modules|improve|international|configure|addons|_profiler|product|combination|specific-price)/(.*)$ {
        try_files $uri $uri/ /index.php?q=$uri&$args $admin_dir/index.php$is_args$args;
    }

    # Cloudflare / Max CDN fix
    location ~* \.(eot|otf|ttf|woff|woff2)$ {
        add_header Access-Control-Allow-Origin *;
    }

    # Do not save logs for these
    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        auth_basic off;
        allow all;
        log_not_found off;
        access_log off;
    }

    location / {
        # Redirect pretty urls to index.php
        try_files $uri $uri/ /index.php?$args;

        # Images
        rewrite ^/([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ /img/p/$1/$1$2$3.jpg last;
        rewrite ^/([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ /img/p/$1/$2/$1$2$3$4.jpg last;
        rewrite ^/([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ /img/p/$1/$2/$3/$1$2$3$4$5.jpg last;
        rewrite ^/([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ /img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg last;
        rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ /img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg last;
        rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg last;
        rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg last;
        rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg last;
        rewrite ^/c/([0-9]+)(-[.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+.jpg$ /img/c/$1$2$3.jpg last;
        rewrite ^/c/([a-zA-Z_-]+)(-[0-9]+)?/.+.jpg$ /img/c/$1$2.jpg last;

        # AlphaImageLoader for IE and fancybox
        rewrite ^images_ie/?([^/]+)\.(jpe?g|png|gif)$ js/jquery/plugins/fancybox/images/$1.$2 last;

        # Web service API
        rewrite ^/api/?(.*)$ /webservice/dispatcher.php?url=$1 last;

    }

    # Allow access to the ACME Challenge for Let's Encrypt
    location ~ /\.well-known\/acme-challenge {
      allow all;
    }

    # Block all files with these extensions
    location ~ \.(md|tpl)$ {
      deny all;
    }

    # File security
    # .htaccess .DS_Store .htpasswd etc
    location ~ /\. {
        deny all;
    }
    # Source code directories
    location ~ ^/(app|bin|cache|classes|config|controllers|docs|localization|override|src|tests|tools|translations|travis-scripts|vendor|var)/ {
        deny all;
    }
    # Prevent exposing other sensitive files
    location ~ \.(yml|log|tpl|twig|sass)$ {
        deny all;
    }

    # Prevent injection of php files
    location /upload {
        location ~ \.php$ {
            deny all;
        }
    }
    location /img {
        add_header Cache-Control public;
        expires 1d;

        location ~ \.php$ {
            deny all;
        }
    }

        location ~ .php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+.php)(/.+)$;
                fastcgi_pass unix:/run/php/php7.2-fpm.sock;
                fastcgi_index index.php;
                include fastcgi.conf;
                fastcgi_read_timeout 150;
        }




}

 

Edited by Developer201343 (see edit history)
Link to comment
Share on other sites

  • 3 years later...
  • 4 weeks later...

Hi,

You may need to add a specific location block to handle requests for downloading attachments. Currently, there's no dedicated block for handling attachment downloads.

Ref:

location /index.php {
    # Existing configuration for PHP processing

    # Add a new location block for handling attachment downloads
    if ($request_uri ~* "^/index\.php\?controller=attachment&id_attachment=(\d+)") {
        rewrite ^/index\.php$ /index.php?$args last;
    }
}

This block captures requests for downloading attachments and ensures that the language code is correctly handled in the URL.

  • The try_files directive in the root location block redirects pretty URLs to index.php. Make sure that it properly handles URLs with language codes. You might need to adjust this directive to include language codes in the rewrite rules.
  • Enable detailed logging in Nginx to track how requests for attachment downloads are processed. Look for any errors or unexpected behavior in the logs that might indicate issues with URL handling.
  • Once you've made these adjustments, test downloading attachments with URLs containing language codes to verify that the issue has been resolved. Remember to monitor your Nginx error logs for any new errors that might arise after making changes.

Hope this helps.

Thanks!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...