重构网站时,我在.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;
}
答案 0 :(得分:0)
根据nginx
自己的建议,您应该使用位置块和return
指令
https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/#taxing-rewrites