nginx 重写或位置

nginx 重写或位置

我正在将旧网站迁移到新结构,并且进行了大量以下类型的重写:

location / {
 rewrite ^/foo.html /legacy-page? permanent;
 rewrite ^/bar.html /legacy-page? permanent;
 rewrite ^/org.html /legacy-page? permanent;
 rewrite ^/directory/foo.html /legacy-page? permanent;
 rewrite ^/directory2 /legacy-page? permanent;
 try_files $uri $uri/ /index.php?q=$uri&$args;
}

有没有更好/更有效的方法来处理这些/legacy-page 重写?

答案1

尝试:

rewrite ^/(foo|bar|org|directory/foo).html /legacy-page? permanent;
rewrite ^/directory2 /legacy-page2 permanent;

相关内容