1

我现在有这个规则:

 RewriteRule ^/mp3/(.*)$ /music/$1 [L,R=301]
 RewriteRule ^/activate/(.*) /index.php?p=activate.php&hash=$1 [QSA]
 RewriteRule ^(.*)/([0-9]+)/(.*)$ index.php?p=$1&id=$2&page=$2 [QSA]
 RewriteRule ^(.*)/([0-9]+)$ index.php?p=$1&id=$2&page=$2 [QSA]
 RewriteRule ^(.*)/$ index.php?p=$1 [QSA]

但转移到 Nginx,我已经创建了这些规则,但现在工作,我只得到 404:

location / {
    rewrite ^/mp3/(.*) /music/$1 permanent;
    rewrite ^/activate/(.*) /index.php?p=activate.php&hash=$1 permanent;
    rewrite ^(.*)/([0-9]+)/(.*)$ index.php?p=$1&id=$2&page=$2 break;
    rewrite ^(.*)/([0-9]+)$ index.php?p=$1&id=$2&page=$2 break;
    rewrite ^(.*)/$ index.php?p=$1 break;
}

如何将 QSA 规则转换为 Nginx?

4

1 回答 1

0

与 apache 的 mod_rewrite 不同,您可以匹配 nginxrewrite命令中的查询字符串。所以你想要这样的东西:

location / {
    rewrite ^/mp3/(.*) /music/$1 permanent;
    rewrite ^/activate/([^\?]*)(?:\?(.*))? /index.php?p=activate.php&hash=$1&$2 permanent;
    rewrite ^(.*)/([0-9]+)/([^\?]*)(?:\?(.*))?$ index.php?p=$1&id=$2&page=$2&$3 break;
    rewrite ^(.*)/([0-9]+)(?:\?(.*))?$ index.php?p=$1&id=$2&page=$2&$3 break;
    rewrite ^(.*)/(?:\?(.*))?$ index.php?p=$1&$2 break;
}
于 2013-04-11T02:16:13.390 回答