【问题标题】:Traefik Kubernetes 301 RedirectTraefik Ku​​bernetes 301 重定向
【发布时间】:2021-04-08 08:11:08
【问题描述】:

我通过 helm chart 安装了 traefik。

我有一个域:example.com

它有一些博客文章。

我现在创建了一个子域:subdomain.example.com

我有我的博客网址列表:

/blog-1
/blog-2

基域和子域都在同一个集群上。

我想要 301 重定向,这样如果有人尝试访问:

example.com/blog-1

他们将被重定向到:

subdomain.example.com/blog-1

我不想只用我的博客网址列表直接使用通配符。

谢谢

这是我重定向到 https 的中间件

apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: https-only
  namespace: exmaple
spec:
  redirectScheme:
    scheme: https
    permanent: true

重定向是:

apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: test-redirectregex
spec:
  redirectRegex:
    regex: "https://example.com"
    replacement: "https://subdomain.example.com"
    permanent: true

我可以在同一个中间件中有多个 redirectRegex 吗? 然后我会有很多重定向每个网址

【问题讨论】:

    标签: redirect kubernetes traefik http-redirect


    【解决方案1】:

    每个中间件只有一个重定向,但您可以拥有任意数量的中间件。

    但在这种情况下,您可以使用正则表达式:

      redirectRegex:
        regex: "https://example.com/(blog-1|blog-2|whatever)"
        replacement: "https://subdomain.example.com/$1"
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-13
    • 1970-01-01
    • 1970-01-01
    • 2010-09-26
    • 2013-01-07
    • 2018-03-06
    • 2012-02-06
    • 2010-11-05
    相关资源
    最近更新 更多