将重写从 htaccess 转换为 nginx

Converting a rewrite from htaccess to nginx

我目前正在 Apache 中使用此 htaccess 代码将地址栏中的 URLhttp://www.domain.com/list?m=100 更改为 http://www.domain.com/list/100

RewriteEngine On

<IfModule mod_rewrite.c>
  RewriteCond %{REQUEST_FILENAME} !-d 
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^([^.]*)$ index.php?m= [QSA,L]
</IfModule>

上面的 htaccess 在 /list 目录下。

我曾尝试将其转换为 nginx(使用 http://winginx.com/en/htaccess),但无法成功。这是我试过的

location /list/ {
    if (!-e $request_filename){
        rewrite ^/([^.]*)$ /index.php?m= break;
    }
}

上面只是下载了PHP代码。我也尝试将中断更改为最后,但它只是打开主页(地址栏中的 url 更改为 http://www.domain.com/list/100)。有什么建议可以让它发挥作用吗?

你不需要转换所有东西,使用这个:

location /list/ {
   rewrite ^/list/(.*)$ /index.php?m= last;
}

之后不要忘记重启 nginx 以查看更改。