1

nginx 去掉转发形成的双斜杠

 1 year ago
source link: https://zhiqiang.org/it/remove-nginx-redirect-two-slashs.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

nginx 去掉转发形成的双斜杠

作者: 张志强

, 发表于 2022-06-22

, 共 428 字 , 共阅读 7 次

在 nginx 里设置了一个转发:

server {
    localtion /blog {
        rewrite .* https://zhiqiang.org permanent;
    }
}

会发生一个奇怪的现象:当访问 https://zhiqiang.org/blog时,会被转发到https://zhiqiang.org//。各种修改也不能去掉最后的这两个斜杠。

最后只好在最前面再添加一个规则:

server {
    if ($request_uri ~* "\/\/") {
        rewrite ^/(.*)      $scheme://$host/$1    permanent;
    }

    localtion /blog {
        rewrite .* https://zhiqiang.org permanent;
    }
}

这样才清净下来。

Q. E. D.

avatar-0.jpg
在绿野亲子约伴走了一次超虐的路线,从龙泉寺出发走熬狱沟,上到上方寺,再沿山脊向南走到高压线塔,再从南线登山步道经泉眼下山。总里程约 9 公里,爬升约 900 米。

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK