从.htaccess转换nginx规则

我无法将一些.htaccess规则转换为nginx服务器。

RewriteRule ^$ index.php [L] RewriteRule ^([A-Za-z0-9-]+)?$ index.php?section=$1 [L] RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ index.php?section=$1&go=$2 [L] RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ index.php?section=$1&go=$2&action=$3 [L] 

有人能够帮助转换和解释这些正则expression式将如何转换为nginx?

我不确定的语法,根据nginx文档我已经尝试了以下内容:

 server { rewrite ^([A-Za-z0-9-]+)?$ index.php?section=$1&go=$2; } 

我也尝试了一个根位置块,如下所示。 我不知道try_files如何影响这个。

 location / { rewrite ^$ /index.php break; rewrite ^([A-Za-z0-9-]+)?$ /index.php?section=$1 break; rewrite ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ /index.php?section=$1&go=$2 break; rewrite ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ /index.php?section=$1&go=$2&action=$3 break; rewrite ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ /index.php?section=$1&go=$2&action=$3&id=$4 break; try_files $uri $uri/ /index.php?$args; } 

这似乎并没有工作。 这是否需要首先放置在一个位置块?

我正在testing的url如下。 主机名已被删除,因为我不允许分享它。

 http://www.example.com/entry http://www.example.com/volunteers http://www.example.com/contact 

基本上这个页面正在被加载,就好像index.php正在被访问一样,如果这是有意义的,这些部分就不会被加载。 似乎没有任何东西传入index.php脚本。

location块是您的rewrite指令通常的地方,所以你说得对。

在您的configuration中明显缺less的唯一东西是正则expression式中的前导/

 location / { rewrite ^/$ /index.php break; rewrite ^/([A-Za-z0-9-]+)?$ /index.php?section=$1 break; rewrite ^/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ /index.php?section=$1&go=$2 break; }