Py学习  »  NGINX

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

MarkE • 4 年前 • 287 次点击  

当我重构我的站点时,我有许多在.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;
}
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/38185
 
287 次点击  
文章 [ 1 ]  |  最新文章 4 年前
Shawn C.
Reply   •   1 楼
Shawn C.    5 年前

基于 nginx 你应该使用一个定位块和一个 return 指令

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