.htaccess prestashop/nginx multi-lang“;未指定输入文件";关于index.php请求

.htaccess prestashop/nginx multi-lang“;未指定输入文件";关于index.php请求,.htaccess,mod-rewrite,nginx,url-rewriting,prestashop,.htaccess,Mod Rewrite,Nginx,Url Rewriting,Prestashop,我们已经在nginx上顺利运行了prestashop 当我们在站点上启用多语言时,面临以下问题: 通常在付款后,如果没有multi-lang,您将被重定向回此页面: 在我们的apache环境中,这很好地工作 在nginx上, 启用多语言时发生的情况是,当您访问上述链接时,lang参数将添加到url(不应添加到url时): 或 这会导致用户遇到预设错误“未指定输入文件” 上述重定向不应发生,一旦完成订单,以下URL必须在不重定向的情况下工作,也不能在index.php之前添加“en”或“fr

我们已经在nginx上顺利运行了prestashop

当我们在站点上启用多语言时,面临以下问题:

通常在付款后,如果没有multi-lang,您将被重定向回此页面:

在我们的apache环境中,这很好地工作

在nginx上, 启用多语言时发生的情况是,当您访问上述链接时,lang参数将添加到url(不应添加到url时):

这会导致用户遇到预设错误“未指定输入文件”

上述重定向不应发生,一旦完成订单,以下URL必须在不重定向的情况下工作,也不能在index.php之前添加“en”或“fr”代码:

nginx的配置如下:

    location /favicon {
            alias /var/www/vhosts/11footballclub.com/httpdocs/img/facicon.ico;
    }

      location / {
          index index.html index.htm index.php;


    try_files $uri $uri/ /index.php?$args;
      }

      location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
          access_log        off;
          log_not_found     off;
          expires           360d;
      }

      location ~ /\. {
          access_log off;
          log_not_found off;
          deny all;
      }

      location = /favicon.ico {
          log_not_found off;
          access_log off;
      }

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

      location ~ \.php$ {
          include /etc/nginx/fastcgi_params;
          fastcgi_pass  127.0.0.1:9000;
          fastcgi_index index.php;
          fastcgi_param SCRIPT_FILENAME /var/www/vhosts/11footballclub.com/httpdocs$fastcgi_script_name;
          fastcgi_param PHP_VALUE max_execution_time=180;
      }

      # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
      location ~ /\. {
          deny all;
          access_log off;
          log_not_found off;
      }



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

      rewrite "^/c/([0-9]+)(\-[_a-zA-Z0-9-]*)/(.*)\.jpg$" /img/c/$1$2.jpg last;
      rewrite "^/c/([_a-zA-Z-]+)/(.*)\.jpg$" /img/c/$1.jpg last;

      rewrite "^/([a-z0-9]+)\-([a-z0-9]+)(\-[_a-zA-Z0-9-]*)/(\P{M}\p{M}*)*\.jpg$" /img/p/$1-$2$3.jpg last;
      rewrite "^/([0-9]+)\-([0-9]+)/(\P{M}\p{M}*)*\.jpg$" /img/p/$1-$2.jpg last;
      rewrite "^/([0-9])(\-[_a-zA-Z0-9-]*)?/(\P{M}\p{M}*)*\.jpg$" /img/p/$1/$1$2.jpg last;
      rewrite "^/([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/(\P{M}\p{M}*)*\.jpg$" /img/p/$1/$2/$1$2$3.jpg last;
      rewrite "^/([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/(\P{M}\p{M}*)*\.jpg$" /img/p/$1/$2/$3/$1$2$3$4.jpg last;
     rewrite "^/([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/(\P{M}\p{M}*)*\.jpg$" /img/p/$1/$2/$3/$4/$1$2$3$4$5.jpg last;
      rewrite "^/([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/(\P{M}\p{M}*)*\.jpg$" /img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6.jpg last;
      rewrite "^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/(\P{M}\p{M}*)*\.jpg$" /img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7.jpg last;
      rewrite "^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/(\P{M}\p{M}*)*\.jpg$" /img/p/$1/$2/$3/$4/$5/$6/$7/$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])([0-9])(\-[_a-zA-Z0-9-]*)?/(\P{M}\p{M}*)*\.jpg$" /img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9.jpg last;


    #rewrite "^/index.php\?controller=http(.*)$" $1 last;


      rewrite "^/([0-9]+)\-(\P{M}\p{M}*)+\.html(.*)$" /index.php?controller=product&id_product=$1$3 last;
      rewrite "^/([0-9]+)\-([a-zA-Z0-9-]*)(.*)$" /index.php?controller=category&id_category=$1$3 last;
      rewrite "^/([a-zA-Z0-9-]*)/([0-9]+)\-([a-zA-Z0-9-]*)\.html(.*)$" /index.php?controller=product&id_product=$2$4 last;
      rewrite "^/([0-9]+)__([a-zA-Z0-9-]*)(.*)$" /index.php?controller=supplier&id_supplier=$1$3 last;
      rewrite "^/([0-9]+)_([a-zA-Z0-9-]*)(.*)$" /index.php?controller=manufacturer&id_manufacturer=$1$3 last;
      rewrite "^/content/([0-9]+)\-([a-zA-Z0-9-]*)(.*)$" /index.php?controller=cms&id_cms=$1$3 last;
      rewrite "^/content/category/([0-9]+)\-([a-zA-Z0-9-]*)(.*)$" /index.php?controller=cms&id_cms_category=$1$3 last;

    rewrite "^/module/([_a-zA-Z0-9-]*)/([_a-zA-Z0-9-]*)$" /index.php?fc=module&module=$1&controller=$2 last;



      rewrite ^/page-not-found$ /index.php?controller=404 last;
      rewrite ^/address$ /index.php?controller=address last;
      rewrite ^/addresses$ /index.php?controller=addresses last;
      rewrite ^/authentication$ /index.php?controller=authentication last;
      rewrite ^/best-sales$ /index.php?controller=best-sales last;
      rewrite ^/cart$ /index.php?controller=cart last;
      rewrite ^/contact-us$ /index.php?controller=contact-form last;
      rewrite ^/discount$ /index.php?controller=discount last;
      rewrite ^/guest-tracking$ /index.php?controller=guest-tracking last;
      rewrite ^/order-history$ /index.php?controller=history last;
      rewrite ^/identity$ /index.php?controller=identity last;
      rewrite ^/manufacturers$ /index.php?controller=manufacturer last;
      rewrite ^/my-account$ /index.php?controller=my-account last;

     rewrite ^/new-products$ /index.php?controller=new-products last;
      rewrite ^/order$ /index.php?controller=order last;
      rewrite ^/order-follow$ /index.php?controller=order-follow last;
      rewrite ^/quick-order$ /index.php?controller=order-opc last;
      rewrite ^/order-slip$ /index.php?controller=order-slip last;
      rewrite ^/password-recovery$ /index.php?controller=password last;
      rewrite ^/prices-drop$ /index.php?controller=prices-drop last;
      rewrite ^/search$ /index.php?controller=search last;
      rewrite ^/sitemap$ /index.php?controller=sitemap last;
      rewrite ^/stores$ /index.php?controller=stores last;
      rewrite ^/supplier$ /index.php?controller=supplier last;

      location ~* \.(gif)$ {
        expires 2592000s;
      }

      location ~* \.(jpeg|jpg)$ {
        expires 2592000s;
      }

      location ~* \.(png)$ {
        expires 2592000s;
      }

      location ~* \.(css)$ {
        expires 604800s;
      }

      location ~* \.(js|jsonp)$ {
        expires 604800s;
      }

将此位置块添加到配置文件中

location ~ (/lang1|/lang2)/index\.php$ {
    try_files $uri $uri/ /index.php?$args;
}
其中
lang1
lang2
是您网站中使用的语言(例如“en”、“ru”等)。您可以通过在括号内添加
|/language_name
来添加更多语言


注意:修改后不要忘记重新启动/重新加载nginx服务器。

下面是一个配置示例,它可以很好地与nginx、PrestaShop v1.6.1.x(支持两种语言:EN/FR)、PHP-FPM 7.2和Let's Encrypt的SSL证书配合使用

如果复制/粘贴此示例(在/etc/nginx/sites enabled文件夹中),请记住:

  • 用您的域名替换“myshop.com”
  • 将“myadminfolder”替换为您的PrestaShop管理员文件夹名称
  • 将“(/fr |/en)”替换为实际使用的语言代码
  • 使用Let's Encrypt certbot工具生成SSL证书(可选,如果不想使用SSL,请删除此部分)
  • 确保您的PHP-FPM套接字文件位于/var/run/PHP/php7.2-FPM.sock中,否则请修改此路径
  • 谢谢@Canarius的提示

    server {
            listen [::]:80;
            listen 80;
            server_name myshopname.com www.myshop.com
            root /var/www/myshopname.com/;
            index index.php index.html;
            access_log /var/log/nginx/myshopname.com.access_log;
            error_log /var/log/nginx/myshopname.com.error_log;
    
            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;
            }
    
            # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
            location ~ /\. {
                    deny all;
                    access_log off;
                    log_not_found off;
            }
    
            gzip on;
            gzip_disable "msie6";
            gzip_vary on;
            gzip_proxied any;
            gzip_comp_level 1;
            gzip_buffers 16 8k;
            gzip_http_version 1.0;
            gzip_types application/json text/css application/javascript;
    
            rewrite ^/api/?(.*)$ /webservice/dispatcher.php?url=$1 last;
            rewrite ^/([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$1$2.jpg last;
            rewrite ^/([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$1$2$3.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.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.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.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.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.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.jpg last;
            rewrite ^/c/([0-9]+)(-[_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ /img/c/$1$2.jpg last;
            rewrite ^/c/([a-zA-Z-]+)(-[0-9]+)?/.+\.jpg$ /img/c/$1.jpg last;
            rewrite ^/([0-9]+)(-[_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ /img/c/$1$2.jpg last;
    
            location ~ (/fr|/en)/index\.php$ {
                    try_files $uri $uri/ /index.php?$args;
            }
    
            try_files $uri $uri/ /index.php?$args;
    
            location /myadminfolder/ {
                    if (!-e $request_filename) {
                            rewrite ^/.*$ /myadminfolder/index.php last;
                    }
            }
    
            location ~ .php$ {
                    fastcgi_split_path_info ^(.+.php)(/.*)$;
                    fastcgi_keep_conn on;
                    include /etc/nginx/fastcgi_params;
                    include snippets/fastcgi-php.conf;
                    fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    fastcgi_read_timeout 300;
            }
    
        listen [::]:443 ssl; # managed by Certbot
        listen 443 ssl; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/www.myshopname.com/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/www.myshopname.com/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    }