lanxing 发表于 2018-4-9 00:52:05

lnmp怎么在opencart2.0.3.1中添加伪静态

制作伪静态文件opencart.conf 内容
location / {
         
rewrite ^/sitemap.xml$ /index.php?route=feed/google_sitemap last;

rewrite ^/googlebase.xml$ /index.php?route=feed/google_base last;

rewrite ^/system/download/(.*) /index.php?route=error/not_found last;
if (!-f $request_filename){

set $rule_3 1$rule_3;
}
if (!-d $request_filename){

set $rule_3 2$rule_3;
}
if ($uri !~ ".*\.(ico|gif|jpg|jpeg|png|js|css)"){

set $rule_3 3$rule_3;
}
if ($rule_3 = "321"){

rewrite ^/([^?]*) /index.php?_route_=$1 last;
}

      }


把文件opencart.conf /usr/local/nginx/conf/rewrite 里面
在/usr/local/nginx/conf/vhost 中修改对应的规则
例如 9,57行 修改为include rewrite/opencart.conf;

licess 发表于 2018-4-9 09:54:46

从网上找到的opencart 2.1版本的,修改后的完整虚拟主机配置如下
server {
    server_name 域名;
    root /home/wwwroot/网站目录;
    index index.php index.html;

    listen 80;

    include enable-php.conf;

    location /image/data {
      autoindex on;
    }
    location /admin {
      index index.php;
    }
    location / {
      try_files $uri @opencart;
    }
    location @opencart {
      rewrite ^/(.+)$ /index.php?_route_=$1 last;
    }
   
    # Make sure files with the following extensions do not get loaded by nginx because nginx would display the source code, and these files can contain PASSWORDS!
    location ~* \.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(\..*|Entries.*|Repository|Root|Tag|Template)$|\.php_ {
      deny all;
    }
    # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
    location ~ /\. {
      deny all;
      access_log off;
      log_not_found off;
    }
    location ~*\.(jpg|jpeg|png|gif|css|js|ico)$ {
      expires max;
      log_not_found off;
    }
   
    access_log /home/wwwlog/域名.log;
}

好像有说需要开pathinfo的,如果要pathinfo的话把 include enable-php.conf; 改成 include enable-php-pathinfo.conf;
页: [1]
查看完整版本: lnmp怎么在opencart2.0.3.1中添加伪静态