社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  NGINX

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

MarkE • 5 年前 • 372 次点击  

当我重构我的站点时,我有许多在.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
 
372 次点击  
文章 [ 1 ]  |  最新文章 5 年前
Shawn C.
Reply   •   1 楼
Shawn C.    6 年前

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

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