【问题标题】:Nginx temporary redirect for new url with replacingNginx 临时重定向新 url 并替换
【发布时间】:2021-05-21 18:06:06
【问题描述】:

我们将把 URL 从 ourdomain.com/en(ourdomain.com 今天重定向到 ourdomain.com/en)更改为 ourdomain.com/

我们的许多网址都采用 ourdomain.com/en/company 格式。如果它在第一个斜杠之后包含 en,我们希望它成为 ourdomain.com/company。我的正则表达式技能有限,所以我还没有完全弄清楚(在我们的位置块/中)。同时,如果我让它工作,会告诉你任何建议吗?提前致谢。

【问题讨论】:

    标签: nginx redirect


    【解决方案1】:
      location /en/ {
        rewrite /en(.+) $1 permanent;
      }
    

    从/en/anything 永久重定向到/anything。这不包括对yourdomain.com/en 的请求(末尾没有斜线)。如果您想解决此问题,请专门为该情况添加另一个位置:

    location = /en {
      return 301 https://$host/;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-25
      • 2022-07-06
      • 2019-01-03
      • 1970-01-01
      相关资源
      最近更新 更多