如何将mod_rewrite(QSA选项)转换为Nginx等效?

jum*_*oel 11 regex mod-rewrite nginx

我想将以下mod_rewrite规则转换为Nginx等价物:

RewriteRule ^foo/(.*)$ /bar/index.php?title=$1 [PT,L,QSA]
RewriteRule ^foo/*$ /bar/index.php [L,QSA]
Run Code Online (Sandbox Code Playgroud)

到目前为止,我有:

rewrite ^foo/(.*)$ /bar/index.php?title=$1&$query_string last;
rewrite ^foo/?$ /bar/index.php?$query_string break;
Run Code Online (Sandbox Code Playgroud)

问题是(我认为!)查询字符串没有被追加.我还没有找到将QSA参数移植到Nginx的方法.

Mik*_*age 17

QSA在NGINX中是自动的.

如果你不想要它,添加?到你新位置的尽头

重写^/foo /bar/index.php?持续;


jum*_*oel 5

这些重写规则使脚本工作:

rewrite ^/foo/([^?]*)(?:\?(.*))? /bar/index.php?title=$1&$2;
rewrite ^/foo /bar/index.php;
Run Code Online (Sandbox Code Playgroud)