首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >哪种形式的nginx重写更有效?

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

Stack Overflow用户
提问于 2018-10-10 03:04:45
回答 1查看 79关注 0票数 0

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

代码语言:javascript
复制
# 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;
}
EN

回答 1

Stack Overflow用户

发布于 2018-10-10 03:25:42

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

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

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52727765

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档