Regex 哪种形式的nginx重写更有效?
我重构网站时,在.htaccess中有很多重定向。现在我想为nginx重新创建它们。以下是等效的吗?哪种样式更有效Regex 哪种形式的nginx重写更有效?,regex,nginx,url-rewriting,processing-efficiency,Regex,Nginx,Url Rewriting,Processing Efficiency,我重构网站时,在.htaccess中有很多重定向。现在我想为nginx重新创建它们。以下是等效的吗?哪种样式更有效 # Style A location / { location /foo/123/old { rewrite ^(.*) /bar/123/ permanent; } location /baz/456/old { rewrite ^(.*) /bar/456/ permanent; } } # Style B lo
# 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
指令
但“重写征税”一节是解决将URL不变地传递给新主机的问题,确保返回仅通过现有URI更有效。这并没有说明在重写中“location”与regex的匹配。