将apache http htaccess转换为Prestashop 1.6多商店的nginx配置

时间:2016-08-18 09:48:47

标签: apache .htaccess nginx prestashop prestashop-1.6

我正在运行Prestashop 1.6并启用了多个存储。 默认网址为http://192.168.1.217/prestashop161 我在这个网址http://192.168.1.217/prestashop161/shopa

有另一家商店

当您更改设置时,Prestashop会自动创建htaccess文件,但是我使用的是nginx,而我正在尝试移植配置。 以下是htacess中为我生成的内容:

#Domain: 192.168.1.217
RewriteCond %{HTTP_HOST} ^192.168.1.217$
RewriteRule . - [E=REWRITEBASE:/prestashop161/shopa/]
RewriteRule ^api$ api/ [L]

RewriteRule ^api/(.*)$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1 [QSA,L]

这就是我在nginx中试过的:

location /prestashop161 {
    root   E:\servers\htdocs;
    index  index.html index.htm index.php;
    rewrite '^/(shopa)$'     /$1/ redirect;
    rewrite ^/api$ /api/ last;
    rewrite ^/api/(.*)$ webservice/dispatcher.php?url=$1 last;
}

1 个答案:

答案 0 :(得分:2)

我根据官方文档找出了如何做到这一点:http://doc.prestashop.com/display/PS16/System+Administrator+Guide#SystemAdministratorGuide-NginxfriendlyURLs

仅当您启用友好URL时才会起作用,否则它将重定向到无限循环。

以下是步骤:

  1. 启用友好网址

  2. 将此代码粘贴到主店

    location /prestashop161/{
        root   E:\servers\htdocs;
        index /prestashop161/index.php;
    
        rewrite ^/prestashop161/api/?(.*)$ /prestashop161/webservice/dispatcher.php?url=$1 last;
        rewrite ^/prestashop161/([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /prestashop161/img/p/$1/$1$2.jpg last;
        rewrite ^/prestashop161/([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /prestashop161/img/p/$1/$2/$1$2$3.jpg last;
        rewrite ^/prestashop161/([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /prestashop161/img/p/$1/$2/$3/$1$2$3$4.jpg last;
        rewrite ^/prestashop161/([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /prestashop161/img/p/$1/$2/$3/$4/$1$2$3$4$5.jpg last;
        rewrite ^/prestashop161/([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /prestashop161/img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6.jpg last;
        rewrite ^/prestashop161/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /prestashop161/img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7.jpg last;
        rewrite ^/prestashop161/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /prestashop161/img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8.jpg last;
        rewrite ^/prestashop161/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /prestashop161/img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9.jpg last;
        rewrite ^/prestashop161/c/([0-9]+)(-[_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ /prestashop161/img/c/$1$2.jpg last;
        rewrite ^/prestashop161/c/([a-zA-Z-]+)(-[0-9]+)?/.+\.jpg$ /prestashop161/img/c/$1.jpg last;
        rewrite ^/prestashop161/([0-9]+)(-[_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ /prestashop161/img/c/$1$2.jpg last;
        try_files $uri $uri/ /prestashop161/index.php?$args;
    }
    
  3. 粘贴shopa

    的此代码
    location /prestashop161/shopa/ {
        rewrite ^/prestashop161/shopa/(.*)$ /prestashop161/$1 last;
        try_files $uri $uri/ /prestashop161/index.php?$args;
    }
    
  4. 就是这样