apache mod-rewrite 到 nginx 重写

apache mod-rewrite 到 nginx 重写

我刚刚从 Apache 更改为 NGINX,并且我正在使用 Zencart 和 Ultimate SEO 来获得友好的 URL。我尝试将 .htaccess 规则转换为 NGINX,但出现“未指定输入文件”或 404 错误。我的原始 .htaccess 如下:

     ErrorDocument 404 /404.html


     Options +FollowSymLinks
     RewriteEngine On




     # From Ultimate SEO URLs
     RewriteRule ^(.*)-p-(.*).html$ index\.php?main_page=product_info&products_id=$2&%{QUERY_STRING} [L]
     RewriteRule ^(.*)-c-(.*).html$ index\.php?main_page=index&cPath=$2&%{QUERY_STRING} [L]
     RewriteRule ^(.*)-m-([0-9]+).html$ index\.php?main_page=index&manufacturers_id=$2&%{QUERY_STRING} [L]
     RewriteRule ^(.*)-pi-([0-9]+).html$ index\.php?main_page=popup_image&pID=$2&%{QUERY_STRING} [L]
     RewriteRule ^(.*)-pr-([0-9]+).html$ index\.php?main_page=product_reviews&products_id=$2&%{QUERY_STRING} [L]
     RewriteRule ^(.*)-pri-([0-9]+).html$ index\.php?main_page=product_reviews_info&products_id=$2&%{QUERY_STRING} [L]
     RewriteRule ^(.*)-ezp-([0-9]+).html$ index\.php?main_page=page&id=$2&%{QUERY_STRING} [L]



     # All other pages
     # Don't rewrite real files or directories
     RewriteCond %{REQUEST_FILENAME} !-f [NC] 
     RewriteCond %{REQUEST_FILENAME} !-d
     RewriteRule ^(.*).html$ index\.php?main_page=$1&%{QUERY_STRING} [L]

这是我在 NGINX 的 virtual.conf 中添加的内容

     rewrite ^/(.*)-p-(.*).html$ /index\.php?main_page=product_info&products_id=$2&$args last;
     rewrite ^/(.*)-c-(.*).html$ /index\.php?main_page=index&cPath=$2&$args last;
     rewrite ^/(.*)-m-([0-9]+).html$ /index\.php?main_page=index&manufacturers_id=$2&$args last;
     rewrite ^/(.*)-pi-([0-9]+).html$ /index\.php?main_page=popup_image&pID=$2&$args last;
     rewrite ^/(.*)-pr-([0-9]+).html$ /index\.php?main_page=product_reviews&products_id=$2&$args last;
     rewrite ^/(.*)-pri-([0-9]+).html$ /index\.php?main_page=product_reviews_info&products_id=$2&$args last;
     rewrite ^/(.*)-ezp-([0-9]+).html$ /index\.php?main_page=page&id=$2&$args last;
     if (!-f $request_filename){
     set $rule_7 1$rule_7;
    }
    if (!-d $request_filename){
    set $rule_7 2$rule_7;
    }
    if ($rule_7 = "21"){
    rewrite ^/(.*).html$ /index\.php?main_page=$1&$args last;
    }

        }

知道我做错了什么吗?

彼得

相关内容