我现在有这条规则:
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?
答案 0 :(得分:0)
与apache的mod_rewrite不同,可以匹配nginx的rewrite
命令中的查询字符串。所以你想要的东西是:
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;
}