哪种形式的nginx重写更有效?



当我重构我的网站时,我有一堆重定向在.htaccess中。 现在我想为 nginx 重新创建它们。 以下是否等效,哪种样式更有效?

# Style A
location / {
location /foo/123/old {
rewrite ^(.*) /bar/123/ permanent;
}
location /baz/456/old {
rewrite ^(.*) /bar/456/ permanent;
}
}
# Style B
location / {
rewrite ^/foo/123/old/?$ /bar/123/ permanent;
rewrite ^/baz/456/old//?$ /bar/456/ permanent;
}

根据nginx自己的建议,您应该使用位置块和return指令

https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/#taxing-rewrites

最新更新