【问题标题】:Redirect using variables in NGINX在 NGINX 中使用变量重定向
【发布时间】:2019-08-04 05:16:08
【问题描述】:

我尝试使用正则表达式在我的 NGINX 服务器中创建重定向。

更具体地说,我想将遵循 example.com/a/b/c 模式的 URL 重定向到 example.com/b/c。我相信为了做到这一点,我需要将 URL 的其余部分(在示例中为 /b/c)保存在一个变量中。

【问题讨论】:

  • 什么是a、b 和c?它们都是通配符吗(例如[^/]+)。可能是这样的:rewrite ^/[^/]+(/[^/]+/[^/]+)$ $1 redirect;

标签: variables nginx redirect configuration


【解决方案1】:

如果我理解正确,你想要达到的目标就是这样

location ~ /somelocation/(.*)$ {
    return 301 https://example.com/$1;
}

【讨论】:

    猜你喜欢
    • 2014-02-09
    • 1970-01-01
    • 2016-04-15
    • 2013-06-04
    • 2017-01-09
    • 2013-01-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多