【发布时间】:2021-11-22 12:26:03
【问题描述】:
我在设置 NGINX 时遇到了一些问题,以便所有带有斜杠 (/) 的 URL 都永久重定向到不带斜杠的变体。问题是,除了以/backend 开头的 URL 之外,所有 URL 都应该使用该指令。
例如:
https://example.com/service/ --> https://example.com/service
https://example.com/service/one/ --> https://example.com/service/one
https://example.com/backend/ --> https://example.com/backend/ (should not redirect)
我目前正在使用这个指令:
server {
listen 80;
listen 443 ssl http2;
[...]
location ~ ^/(?!backend)(.+)/$ {
return 301 $1$is_args$args;
}
[...]
}
很遗憾,这里出现以下错误:
https://example.com/service/ --> https://example.com/service/service
有人可以帮我解决这个正则表达式之谜吗?
【问题讨论】:
标签: regex nginx server webserver