Traefik Ku​​bernetes 301 重定向

Traefik Kubernetes 301 Redirect

我通过 helm chart 安装了 traefik。

我有一个域:example.com

它有一些博文。

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

我有我的博客列表 urls:

/blog-1
/blog-2

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

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

example.com/blog-1

他们将被重定向到:

subdomain.example.com/blog-1

我不想只用我的博客列表 urls 使用通配符。

谢谢

这是我用于重定向到 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 吗? 然后我会有很多人来重定向每个 url

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

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

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