【问题标题】:Prestashop 1.6 + Nginx + SSL + Multilingual Site - Rewrite RulesPrestashop 1.6 + Nginx + SSL + 多语言站点 - 重写规则
【发布时间】:2014-08-28 03:03:05
【问题描述】:

我正在努力使用以下设置为 prestashop 设置重写规则

  • Prestashop 1.6
  • SSL
  • 多语言网站(在我的情况下是法语 + 英语)
  • Nginx 1.4.1(这对我发现的 ssl 设置很重要)

我使用了下面的一些参考资料

http://www.prestashop.com/forums/topic/323391-another-nginx-ssl-rewrite-rules-problem/ http://www.prestashop.com/forums/topic/321261-seo-friendly-nginx-rewrites/(非多语种) PRESTASHOP NGINX + REWRITE RULES

并得到下面的这个配置。

一切正常,除了我的一些支付模块返回一个类似的网址 mysite.com/en/index.php?parameter1=1&parameter2=2

这会触发 404

看起来应该将 url 重写为 mysite.com/index.php?parameter1=1&parameter2=2

我有两个问题:

  1. 哪个规则可以处理像 mysite.com/en/16-crews 这样的网址,这些网址运行良好? 它被翻译成什么? (我只是想了解它是如何工作的)

  2. 如何设置重写规则 mysite.com/en/index.php?parameter1=1&parameter2=2mysite.com/index.php?parameter1=1&parameter2=2 它还必须与 /fr/index.php/index.php

    网站的法国方一起使用
    server {
    
    listen   80;
    listen  443 ssl;
    server_name  mysite.com www.mysite.com;
    
    ssl on;
    ssl_certificate /etc/nginx/ssl/mysite.crt;
    ssl_certificate_key /etc/nginx/ssl/mysite.key;
    
    access_log  /var/log/nginx/mysite.access.log;
    error_log   /var/log/nginx/mysite.error.log;
    rewrite_log on;
    
    location / {
    root   /srv/d_h2osensations/www/www.mysite.com/htdocs;
    index  index.html index.htm index.php;
    
    rewrite ^/api/?(.*)$ /webservice/dispatcher.php?url=$1 last;
    rewrite ^/([0-9])(-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*.jpg$ /img/p/$1/$1$2.jpg last;
    rewrite ^/([0-9])([0-9])(-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*.jpg$ /img/p/$1/$2/$1$2$3.jpg last;
    rewrite ^/([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-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-]*)?/[_a-zA-Z0-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-]*)?/[_a-zA-Z0-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-]*)?/[_a-zA-Z0-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-]*)?/[_a-zA-Z0-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-]*)?/[_a-zA-Z0-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-]*)/[_a-zA-Z0-9-]*.jpg$ /img/c/$1$2.jpg last;
    rewrite ^/c/([a-zA-Z-]+)/[a-zA-Z0-9-]+.jpg$ /img/c/$1.jpg last;
    rewrite ^/([0-9]+)(-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*.jpg$ /img/c/$1$2.jpg last;
    try_files $uri $uri/ /index.php?$args;
    }
    
    location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME /srv/d_h2osensations/www/www.mysite.com/htdocs$fastcgi_script_name;
    }
    
    # Deny access to .htaccess
    location ~ /\.ht {
    deny all;
    }
    
    location /phpmyadmin
    { root /usr/share/;
    index index.php index.html index.htm;
    
    location ~ ^/phpmyadmin/(.+\.php)$ {
    try_files $uri =404;
    root /usr/share/;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    }
    location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
    root /usr/share/;
    }
    }
    location /phpMyAdmin {
    rewrite ^/* /phpmyadmin last;
    
    }
    
    }
    

提前致谢。 尼克

【问题讨论】:

    标签: ssl nginx multilingual prestashop-1.6


    【解决方案1】:

    环顾几周后,这对我有用

    server {
        listen 80;
        #listen [::]:80 default_server ipv6only=on;
        listen  443 default ssl;
        #ssl on;
        ssl_certificate /etc/nginx/ssl/cert.crt;
        ssl_certificate_key /etc/nginx/ssl/cert-key.key;
    
        access_log  /var/log/nginx/h2o.prod.access.log;
        error_log   /var/log/nginx/h2o.prod.error.log;
    
    
    
        root /var/www/www.mysite.com/htdocs;
        #root /usr/share/nginx/html;
        index index.html index.htm index.php;
    
        # Make site accessible from http://localhost/
        server_name mysite.com www.mysite.com;
    
    
        #Specify a charset
        charset utf-8;
    
        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-]*)/[_a-zA-Z0-9-]*.jpg$ /img/c/$1$2.jpg last;
        rewrite ^/c/([a-zA-Z-]+)/[a-zA-Z0-9-]+.jpg$ /img/c/$1.jpg last;
        rewrite ^/([0-9]+)(-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*.jpg$ /img/c/$1$2.jpg last;
    
    
        rewrite ^/order$ /index.php?controller=order last;
        if (!-e $request_filename){
            rewrite ^(.*)$ /index.php last;
        }
    
        # Redirect needed to "hide" index.php
        location / {
            try_files $uri $uri/ /index.php?q=$uri&$args;
        }
    
        location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
        }
    
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        location ~ /\.ht {
            deny all;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2011-03-30
      • 2011-01-17
      • 2015-04-18
      • 2013-11-07
      • 2016-02-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多